Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Build ESM -> CJS before running tests in browsers via Saucelabs
Noteworthy tweak is the fact that it seems `zuul` are eagerly loading all `require('whatever-package-or-path')` it sees before pushing the contents to Saucelabs. That was troublesome because we don't want the `esm` package to be loaded when running browser tests. But it was, even though we loaded `esm` conditionally after checking the current Node.js version used. The trick was to not use `require('esm')` but `module.require('esm')` instead, to fool the assumed look-out for `require` somewhere inside `zuul`'s code.
- Loading branch information
Showing
2 changed files
with
12 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,18 @@ | ||
var chai = require('chai'); | ||
var nodejsMajorVersion = Number(process.versions.node.split(".")[0]); | ||
var isRunningInNode = process !== undefined && process.versions.node !== undefined; | ||
|
||
isLegacyNodeVersion = !(nodejsMajorVersion >= 10); | ||
if (isRunningInNode) { | ||
var nodejsMajorVersion = Number(process.versions.node.split('.')[0]); | ||
isLegacyNodeVersion = !(nodejsMajorVersion >= 10); | ||
|
||
if (!isLegacyNodeVersion) { | ||
require = require("esm")(module); | ||
if (!isLegacyNodeVersion) { | ||
// The `zuul` package we use to run tests in browsers via Saucelabs eagerly loads all | ||
// packages it sees being used via `require()`. Because we don't want the `esm` package | ||
// to be loaded when running browser tests, we refer to `require()` via `module.require()` | ||
// because that avoid the mentioned eager loading | ||
module.require = module.require('esm')(module); | ||
} | ||
} | ||
|
||
assert = chai.assert; | ||
chai.should(); | ||
Mustache = require('../mustache'); |