Explorar el Código

Avoid use of `esm` when running tests on legacy Node.js versions

Because `esm` does not support legacy versions of Node.js, at least not
below Node.js 6 as of writing this, we have to avoid using that whenever
tests are running on legacy versions.

But now that the source code (`mustache.js`) is written in ESM syntax,
how on earth are we going to run tests on these legacy versions of
Node.js? We gotta run the build step first, so that we end up with a
`mustache.js` file in CJS, or strictly speaking it will be UMD.

That's kinda pain in the backside isn't it? Yes, but running tests on
legacy versions are not meant to be done locally, but rather in CI. That
means we can easily automate the flow of (1) building the source code
before (2) starting the test suite.

For our futureselves, if we want to stop running tests on legacy
versions of Node.js; the changes introduces in this commit, could be
removed completely.
remove-build-output-from-git
Phillip Johnsen hace 5 años
padre
commit
02c9ef1bf0
Se han modificado 3 ficheros con 11 adiciones y 2 borrados
  1. +1
    -1
      package.json
  2. +2
    -1
      test/cli-test.js
  3. +8
    -0
      test/helper.js

+ 1
- 1
package.json Ver fichero

@@ -31,7 +31,7 @@
"build": "cp mustache.js mustache.mjs && rollup mustache.mjs --file mustache.js --format umd --name Mustache && uglifyjs mustache.js > mustache.min.js",
"test": "npm run test-lint && npm run test-unit",
"test-lint": "eslint mustache.js bin/mustache test/**/*.js",
"test-unit": "mocha --reporter spec --require esm test/*-test.js",
"test-unit": "mocha --reporter spec test/*-test.js",
"test-render": "mocha --reporter spec test/render-test",
"pre-test-browser": "node test/create-browser-suite.js",
"test-browser": "npm run pre-test-browser && zuul -- test/context-test.js test/parse-test.js test/scanner-test.js test/render-test-browser.js",


+ 2
- 1
test/cli-test.js Ver fichero

@@ -9,7 +9,8 @@ var cliPartialsTxt = path.resolve(_files, 'cli_with_partials.txt');
var moduleVersion = require('../package').version;

function changeForOS (command) {
command = command.replace('bin/mustache', 'node --require esm bin/mustache')
var requireFlag = !isLegacyNodeVersion ? '--require esm' : '';
command = command.replace('bin/mustache', 'node ' + requireFlag + ' bin/mustache')

if (process.platform === 'win32') {
return command


+ 8
- 0
test/helper.js Ver fichero

@@ -1,4 +1,12 @@
var chai = require('chai');
var nodejsMajorVersion = Number(process.versions.node.split(".")[0]);

isLegacyNodeVersion = !(nodejsMajorVersion >= 10);

if (!isLegacyNodeVersion) {
require = require("esm")(module);
}

assert = chai.assert;
chai.should();
Mustache = require('../mustache');

Cargando…
Cancelar
Guardar