Skip to content

Commit

Permalink
feature detection in the test environment
Browse files Browse the repository at this point in the history
Previously it was easy to miss testing generators, because of omitting the `--harmony` flag; even `make full` skipped testing generators.
This commit introduces detecting support for certain syntax oriented language features, before running tests.
We can also assume using Node.js v4 or higher, so generator support is implied.
  • Loading branch information
pepkin88 authored and rhendric committed Jul 30, 2018
1 parent 8ac8bb4 commit 03e8b66
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 13 deletions.
5 changes: 1 addition & 4 deletions Makefile
Expand Up @@ -28,7 +28,7 @@ browser/livescript-min.js: browser/livescript.js
package.json: package.json.ls
$(LSC) --compile package.json.ls

.PHONY: build build-browser force full install dev-install test test-harmony coverage loc clean
.PHONY: build build-browser force full install dev-install test coverage loc clean

all: build

Expand All @@ -51,9 +51,6 @@ dev-install: package.json
test: build
./scripts/test

test-harmony: build
node --harmony ./scripts/test

coverage: build
$(ISTANBUL) cover ./scripts/test

Expand Down
1 change: 0 additions & 1 deletion package.json
Expand Up @@ -35,7 +35,6 @@
"scripts": {
"pretest": "make force && make force",
"test": "make test",
"test-harmony": "make test-harmony",
"posttest": "git checkout -- lib"
},
"preferGlobal": true,
Expand Down
1 change: 0 additions & 1 deletion package.json.ls
Expand Up @@ -35,7 +35,6 @@ bin:
scripts:
pretest: 'make force && make force'
test: 'make test'
'test-harmony': 'make test-harmony'
posttest: 'git checkout -- lib'

prefer-global: true
Expand Down
17 changes: 10 additions & 7 deletions scripts/test
Expand Up @@ -21,6 +21,15 @@
return color + text + reset;
}

function testSyntax(code) {
try {
eval(code);
} catch (e) {
return false;
}
return true;
}

var startTime = Date.now();
var passedTests = 0;
var failedTests = 0;
Expand Down Expand Up @@ -156,13 +165,7 @@

var files = fs.readdirSync("test");

if (process.execArgv.indexOf("--harmony") < 0 && process.execArgv.indexOf("--harmony-generators") < 0) {
files.splice(files.indexOf("generators.ls"), 1);
} else {
console.log("Testing with harmony.");
}
var supportsAsync = parseInt(process.versions.node.split('.')[0]) >= 7;
if (supportsAsync) {
if (testSyntax("(async function () {})")) {
console.log("Testing with async.");
} else {
files.splice(files.indexOf("async.ls"), 1);
Expand Down

0 comments on commit 03e8b66

Please sign in to comment.