Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Build for browser on publish

Moved tests around
Ensure browser runs as many tests as possible
  • Loading branch information...
commit fba6b11f4262d3776ce9101aff944e6d1a459657 1 parent 8daa362
@paularmstrong authored
Showing with 61 additions and 52 deletions.
  1. +3 −3 .gitignore
  2. +5 −5 Makefile
  3. +1 −1  package.json
  4. +26 −19 scripts/browser.sh
  5. 0  {dist → scripts/browser}/browser.js
  6. 0  {dist → scripts/browser}/header.js
  7. 0  {dist/test → tests/browser}/expect.js
  8. +3 −1 {dist/test → tests/browser}/index.html
  9. 0  {dist/test → tests/browser}/mocha.css
  10. 0  {dist/test → tests/browser}/mocha.js
  11. +2 −2 tests/{ → node}/filters.test.js
  12. +2 −2 tests/{ → node}/helpers.test.js
  13. +3 −3 tests/{ → node}/parser.test.js
  14. +1 −1  tests/{ → node}/swig.test.js
  15. +1 −1  tests/{ → node}/tags.test.js
  16. +1 −1  tests/{ → node}/tags/autoescape.test.js
  17. +1 −1  tests/{ → node}/tags/block.test.js
  18. +1 −1  tests/{ → node}/tags/else.test.js
  19. +1 −1  tests/{ → node}/tags/extends.test.js
  20. +1 −1  tests/{ → node}/tags/filter.test.js
  21. +1 −1  tests/{ → node}/tags/for.test.js
  22. +1 −1  tests/{ → node}/tags/if.test.js
  23. +2 −2 tests/{ → node}/tags/import.test.js
  24. +1 −1  tests/{ → node}/tags/include.test.js
  25. +1 −1  tests/{ → node}/tags/macro.test.js
  26. +1 −1  tests/{ → node}/tags/parent.test.js
  27. +1 −1  tests/{ → node}/tags/raw.test.js
  28. +1 −1  tests/{ → node}/tags/set.test.js
  29. 0  tests/{ → node}/templates/extends_1.html
  30. 0  tests/{ → node}/templates/extends_2.html
  31. 0  tests/{ → node}/templates/extends_base.html
  32. 0  tests/{ → node}/templates/extends_base2.html
  33. 0  tests/{ → node}/templates/extends_circular1.html
  34. 0  tests/{ → node}/templates/extends_circular2.html
  35. 0  tests/{ → node}/templates/extends_dynamic.html
  36. 0  tests/{ → node}/templates/include_base.html
  37. 0  tests/{ → node}/templates/included.html
  38. 0  tests/{ → node}/templates/included_2.html
  39. 0  tests/{ → node}/templates/includes_notfound.html
  40. 0  tests/{ → node}/templates/macros.html
  41. 0  tests/{ → node}/testutils.js
View
6 .gitignore
@@ -1,8 +1,8 @@
.DS_Store
npm-debug.log
node_modules/*
-dist/browser/*
-dist/test/swig.pack.js
-dist/test/*.test.js
+tests/browser/swig.pack.js
+tests/browser/*.test.js
lib-cov/*
tests/coverage.html
+dist/*
View
10 Makefile
@@ -3,19 +3,19 @@ all:
@cp scripts/githooks/* .git/hooks/
@chmod -R +x .git/hooks/
-browser:
+build:
@scripts/browser.sh
-tests := $(shell find ./tests -name '*.test.js' ! -path "*node_modules/*")
+tests := $(shell find ./tests/node -name '*.test.js' ! -path "*node_modules/*")
reporter = dot
opts =
test:
@node_modules/mocha/bin/mocha --reporter ${reporter} ${opts} ${tests} --globals "_swigglobaltest"
test-browser: browser
- @node_modules/mocha-phantomjs/bin/mocha-phantomjs dist/test/index.html
+ @node_modules/mocha-phantomjs/bin/mocha-phantomjs tests/browser/index.html
-files := $(shell find . -name '*.js' ! -path "*node_modules/*" ! -path "*dist/*")
+files := $(shell find . -name '*.js' ! -path "*node_modules/*" ! -path "*dist/*" ! -path "*tests/browser/*")
lint:
@node_modules/nodelint/nodelint ${files} --config=scripts/config-lint.js
@@ -34,4 +34,4 @@ coverage:
speed:
@node tests/speed.js
-.PHONY: all browser test test-browser lint coverage speed
+.PHONY: all build test test-browser lint coverage speed
View
2  package.json
@@ -34,7 +34,7 @@
"node": ">=0.6.0"
},
"scripts": {
- "prepublish": "npm prune",
+ "prepublish": "npm prune && make build",
"test": "make lint && make test reporter=spec && make test-browser"
},
"bugs": {
View
45 scripts/browser.sh
@@ -4,18 +4,18 @@ echo -ne "Building For Browser"
function package() {
if [[ $1 == 'pack' ]]; then
- BROWSER_FILE="dist/browser/swig.pack.js"
+ BROWSER_FILE="dist/swig.pack.js"
TEMP_FILE="dist/.swig.pack.js"
- MIN_FILE="dist/browser/swig.pack.min.js"
+ MIN_FILE="dist/swig.pack.min.js"
else
- BROWSER_FILE="dist/browser/swig.js"
+ BROWSER_FILE="dist/swig.js"
TEMP_FILE="dist/.swig.js"
- MIN_FILE="dist/browser/swig.min.js"
+ MIN_FILE="dist/swig.min.js"
fi
- cat dist/header.js > $BROWSER_FILE
+ cat scripts/browser/header.js > $BROWSER_FILE
echo -ne "."
- cat dist/browser.js >> $BROWSER_FILE
+ cat scripts/browser/browser.js >> $BROWSER_FILE
echo -ne "."
echo "swig = (function () {" >> $BROWSER_FILE
echo "var swig = {}," >> $BROWSER_FILE
@@ -25,6 +25,14 @@ function package() {
echo "parser = {}," >> $BROWSER_FILE
echo "tags = {};" >> $BROWSER_FILE
+ if [[ $2 == 'test' ]]; then
+ echo "window.dateformat = dateformat;" >> $BROWSER_FILE
+ echo "window.filters = filters;" >> $BROWSER_FILE
+ echo "window.helpers = helpers;" >> $BROWSER_FILE
+ echo "window.parser = parser;" >> $BROWSER_FILE
+ echo "window.tags = tags;" >> $BROWSER_FILE
+ fi
+
if [[ $1 == 'pack' ]]; then
cat node_modules/underscore/underscore.js >> $BROWSER_FILE
echo -ne "."
@@ -76,26 +84,25 @@ function package() {
node_modules/uglify-js/bin/uglifyjs $BROWSER_FILE > $MIN_FILE
}
-rm -rf dist/browser
-mkdir -p dist/browser
+rm -rf dist
+mkdir -p dist
package
-package "pack"
-cp dist/browser/swig.pack.js dist/test/swig.pack.js
+package "pack" "test"
+mv dist/swig.pack.js tests/browser/swig.pack.js
+package "pack"
-find tests -name "*.test.js" ! -name "helpers.test.js" | while read FILE; do
+find tests/node -name "*.test.js" | while read FILE; do
TEST_FILE=$(basename $FILE)
TEMP_FILE="dist/.$TEST_FILE"
NAME=$(sed -e 's/.test.js//' <<< $TEST_FILE)
- cat $FILE > dist/test/$TEST_FILE
-
- cp dist/test/$TEST_FILE $TEMP_FILE
- sed "/require\([^\)]\)/d" <$TEMP_FILE > dist/test/$TEST_FILE
- cp dist/test/$TEST_FILE $TEMP_FILE
- sed "s/testCase/nodeunit.testCase/" <$TEMP_FILE > dist/test/$TEST_FILE
- cp dist/test/$TEST_FILE $TEMP_FILE
- sed "s/__dirname/\'\'/" <$TEMP_FILE > dist/test/$TEST_FILE
+ cat $FILE > tests/browser/$TEST_FILE
+
+ cp tests/browser/$TEST_FILE $TEMP_FILE
+ sed "/require[(]/d" <$TEMP_FILE > tests/browser/$TEST_FILE
+ cp tests/browser/$TEST_FILE $TEMP_FILE
+ sed "s/__dirname/\'\'/" <$TEMP_FILE > tests/browser/$TEST_FILE
rm $TEMP_FILE
echo -ne "."
View
0  dist/browser.js → scripts/browser/browser.js
File renamed without changes
View
0  dist/header.js → scripts/browser/header.js
File renamed without changes
View
0  dist/test/expect.js → tests/browser/expect.js
File renamed without changes
View
4 dist/test/index.html → tests/browser/index.html
@@ -12,13 +12,14 @@
</script>
<script src="swig.pack.js"></script>
- <script src="swig.test.js"></script>
<script src="autoescape.test.js"></script>
<script src="block.test.js"></script>
<script src="else.test.js"></script>
+ <script src="extends.test.js"></script>
<script src="filter.test.js"></script>
<script src="filters.test.js"></script>
<script src="for.test.js"></script>
+ <script src="helpers.test.js"></script>
<script src="if.test.js"></script>
<script src="import.test.js"></script>
<script src="include.test.js"></script>
@@ -27,6 +28,7 @@
<script src="parser.test.js"></script>
<script src="raw.test.js"></script>
<script src="set.test.js"></script>
+ <script src="swig.test.js"></script>
<script src="tags.test.js"></script>
</head>
<body>
View
0  dist/test/mocha.css → tests/browser/mocha.css
File renamed without changes
View
0  dist/test/mocha.js → tests/browser/mocha.js
File renamed without changes
View
4 tests/filters.test.js → tests/node/filters.test.js
@@ -1,7 +1,7 @@
var require = require('./testutils').require,
expect = require('expect.js'),
- swig = require('../lib/swig'),
- DateZ = require('../lib/dateformat').DateZ;
+ swig = require('../../lib/swig'),
+ DateZ = require('../../lib/dateformat').DateZ;
function testFilter(filter, input, output, message) {
it(message, function () {
View
4 tests/helpers.test.js → tests/node/helpers.test.js
@@ -1,7 +1,7 @@
var require = require('./testutils').require,
expect = require('expect.js'),
- swig = require('../lib/swig'),
- helpers = require('../lib/helpers');
+ swig = require('../../lib/swig'),
+ helpers = require('../../lib/helpers');
describe('Helpers', function () {
describe('isLiteral', function () {
View
6 tests/parser.test.js → tests/node/parser.test.js
@@ -1,8 +1,8 @@
var require = require('./testutils').require,
expect = require('expect.js'),
- swig = require('../lib/swig'),
- tags = require('../lib/tags'),
- parser = require('../lib/parser');
+ swig = require('../../lib/swig'),
+ tags = require('../../lib/tags'),
+ parser = require('../../lib/parser');
describe('Tags', function () {
it('undefined tag throws error', function () {
View
2  tests/swig.test.js → tests/node/swig.test.js
@@ -1,6 +1,6 @@
var require = require('./testutils').require,
expect = require('expect.js'),
- swig = require('../lib/swig');
+ swig = require('../../lib/swig');
describe('swig.init', function () {
View
2  tests/tags.test.js → tests/node/tags.test.js
@@ -1,7 +1,7 @@
var require = require('./testutils').require,
expect = require('expect.js'),
util = require('util'),
- swig = require('../lib/swig');
+ swig = require('../../lib/swig');
describe('Custom Tags', function () {
var tags = {
View
2  tests/tags/autoescape.test.js → tests/node/tags/autoescape.test.js
@@ -1,6 +1,6 @@
var require = require('../testutils').require,
expect = require('expect.js'),
- swig = require('../lib/swig');
+ swig = require('../../lib/swig');
describe('Tag: autoescape', function () {
beforeEach(function () {
View
2  tests/tags/block.test.js → tests/node/tags/block.test.js
@@ -1,6 +1,6 @@
var require = require('../testutils').require,
expect = require('expect.js'),
- swig = require('../lib/swig');
+ swig = require('../../lib/swig');
describe('Tag: block', function () {
beforeEach(function () {
View
2  tests/tags/else.test.js → tests/node/tags/else.test.js
@@ -1,6 +1,6 @@
var require = require('../testutils').require,
expect = require('expect.js'),
- swig = require('../lib/swig');
+ swig = require('../../lib/swig');
describe('Tag: else', function () {
beforeEach(function () {
View
2  tests/tags/extends.test.js → tests/node/tags/extends.test.js
@@ -1,6 +1,6 @@
var require = require('../testutils').require,
expect = require('expect.js'),
- swig = require('../lib/swig');
+ swig = require('../../lib/swig');
describe('Tag: extends', function () {
View
2  tests/tags/filter.test.js → tests/node/tags/filter.test.js
@@ -1,6 +1,6 @@
var require = require('../testutils').require,
expect = require('expect.js'),
- swig = require('../lib/swig');
+ swig = require('../../lib/swig');
describe('Tag: filter', function () {
beforeEach(function () {
View
2  tests/tags/for.test.js → tests/node/tags/for.test.js
@@ -1,6 +1,6 @@
var require = require('../testutils').require,
expect = require('expect.js'),
- swig = require('../lib/swig');
+ swig = require('../../lib/swig');
describe('Tag: for', function () {
beforeEach(function () {
View
2  tests/tags/if.test.js → tests/node/tags/if.test.js
@@ -1,6 +1,6 @@
var require = require('../testutils').require,
expect = require('expect.js'),
- swig = require('../lib/swig');
+ swig = require('../../lib/swig');
describe('Tag: if', function () {
beforeEach(function () {
View
4 tests/tags/import.test.js → tests/node/tags/import.test.js
@@ -1,10 +1,10 @@
var require = require('../testutils').require,
expect = require('expect.js'),
- swig = require('../lib/swig');
+ swig = require('../../lib/swig');
describe('Tag: import (for macros)', function () {
beforeEach(function () {
- swig.init({ root: __dirname + '/../../tests/templates' });
+ swig.init({ root: __dirname + '/../templates' });
if (typeof window !== 'undefined') {
swig.compile('{% macro foo %}\nhi!\n{% endmacro %}\n\n{% macro bar baz %}\n{% if baz %}\nbye!\n{% else %}\nfudge.\n{% endif %}\n{% endmacro %}', { filename: 'macros.html' });
}
View
2  tests/tags/include.test.js → tests/node/tags/include.test.js
@@ -1,6 +1,6 @@
var require = require('../testutils').require,
expect = require('expect.js'),
- swig = require('../lib/swig');
+ swig = require('../../lib/swig');
describe('Tag: include', function () {
beforeEach(function () {
View
2  tests/tags/macro.test.js → tests/node/tags/macro.test.js
@@ -1,6 +1,6 @@
var require = require('../testutils').require,
expect = require('expect.js'),
- swig = require('../lib/swig');
+ swig = require('../../lib/swig');
describe('Tag: macro', function () {
beforeEach(function () {
View
2  tests/tags/parent.test.js → tests/node/tags/parent.test.js
@@ -1,6 +1,6 @@
var require = require('../testutils').require,
expect = require('expect.js'),
- swig = require('../lib/swig');
+ swig = require('../../lib/swig');
describe('Tag: parent', function () {
beforeEach(function () {
View
2  tests/tags/raw.test.js → tests/node/tags/raw.test.js
@@ -1,6 +1,6 @@
var require = require('../testutils').require,
expect = require('expect.js'),
- swig = require('../lib/swig');
+ swig = require('../../lib/swig');
describe('Tag: raw', function () {
beforeEach(function () {
View
2  tests/tags/set.test.js → tests/node/tags/set.test.js
@@ -1,6 +1,6 @@
var require = require('../testutils').require,
expect = require('expect.js'),
- swig = require('../lib/swig');
+ swig = require('../../lib/swig');
describe('Tag: set', function () {
beforeEach(function () {
View
0  tests/templates/extends_1.html → tests/node/templates/extends_1.html
File renamed without changes
View
0  tests/templates/extends_2.html → tests/node/templates/extends_2.html
File renamed without changes
View
0  tests/templates/extends_base.html → tests/node/templates/extends_base.html
File renamed without changes
View
0  tests/templates/extends_base2.html → tests/node/templates/extends_base2.html
File renamed without changes
View
0  tests/templates/extends_circular1.html → tests/node/templates/extends_circular1.html
File renamed without changes
View
0  tests/templates/extends_circular2.html → tests/node/templates/extends_circular2.html
File renamed without changes
View
0  tests/templates/extends_dynamic.html → tests/node/templates/extends_dynamic.html
File renamed without changes
View
0  tests/templates/include_base.html → tests/node/templates/include_base.html
File renamed without changes
View
0  tests/templates/included.html → tests/node/templates/included.html
File renamed without changes
View
0  tests/templates/included_2.html → tests/node/templates/included_2.html
File renamed without changes
View
0  tests/templates/includes_notfound.html → tests/node/templates/includes_notfound.html
File renamed without changes
View
0  tests/templates/macros.html → tests/node/templates/macros.html
File renamed without changes
View
0  tests/testutils.js → tests/node/testutils.js
File renamed without changes
Please sign in to comment.
Something went wrong with that request. Please try again.