Skip to content

Commit 56dedb2

Browse files
committed
Instead of testing process.version, use a canary ES6 file.
1 parent f8a6058 commit 56dedb2

File tree

4 files changed

+35
-10
lines changed

4 files changed

+35
-10
lines changed

test/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Unit tests for sqlstring
2+
3+
## Running tests on older node versions
4+
5+
We rely on Travis CI to check compatibility with older Node runtimes.
6+
7+
To locally run tests on an older runtime, for example `0.12`:
8+
9+
```sh
10+
$ npm install --no-save npx
11+
$ ./node_modules/.bin/npx node@0.12 test/run.js
12+
```

test/unit/es6/canary.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// A minimal file that uses ES6 features which will fail to load on
2+
// older browsers.
3+
`I load on ES6`;

test/unit/test-Lexer.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1-
// If we're on a Node runtime that should support ES6, run the ES6 tests.
2-
if (/^v?[0-5][.]/.test(process.version)) {
3-
// The major version is a single digit in [0, 5].
4-
console.info('Skipping ES6 tests for node_version %s', process.version);
5-
} else {
1+
var canRequireES6 = true;
2+
try {
3+
require('./es6/canary');
4+
} catch (ignored) {
5+
canRequireES6 = false;
6+
}
7+
8+
if (canRequireES6) {
69
require('./es6/Lexer');
10+
} else {
11+
console.info('Skipping ES6 tests for node_version %s', process.version);
712
}

test/unit/test-Template.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,16 @@ var assert = require('assert');
22
var SqlString = require('../../');
33
var test = require('utest');
44

5-
// If we're on a Node runtime that should support ES6, run the ES6 tests.
6-
if (/^v?[0-5][.]/.test(process.version)) {
7-
// The major version is a single digit in [0, 5].
5+
var canRequireES6 = true;
6+
try {
7+
require('./es6/canary');
8+
} catch (ignored) {
9+
canRequireES6 = false;
10+
}
11+
12+
if (canRequireES6) {
13+
require('./es6/Template');
14+
} else {
815
console.info('Skipping ES6 tests for node_version %s', process.version);
916

1017
test('Template fallback', {
@@ -17,8 +24,6 @@ if (/^v?[0-5][.]/.test(process.version)) {
1724
});
1825
}
1926
});
20-
} else {
21-
require('./es6/Template');
2227
}
2328

2429
var sql = SqlString.sql;

0 commit comments

Comments
 (0)