소스 검색

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 5 년 전
부모
커밋
02c9ef1bf0
3개의 변경된 파일11개의 추가작업 그리고 2개의 파일을 삭제
  1. +1
    -1
      package.json
  2. +2
    -1
      test/cli-test.js
  3. +8
    -0
      test/helper.js

+ 1
- 1
package.json 파일 보기

@@ -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 파일 보기

@@ -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 파일 보기

@@ -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');

불러오는 중...
취소
저장