Skip to content

Commit

Permalink
Core: Drop support for Node 6 and Node 8, require Node 10+
Browse files Browse the repository at this point in the history
Per <https://github.com/nodejs/Release>, Node 6 and 8 have
reached EOL in 2019.

This allows us to drop the 'resolve' package as dependency,
which is no longer needed as of Node 8.

Closes #1464.
  • Loading branch information
Krinkle authored Jul 26, 2020
1 parent 76f5174 commit d7927a0
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 44 deletions.
12 changes: 6 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
dist
node_modules
build/report
browserstack-run.pid
temp/
docs/_site/
/dist
/node_modules
/build/report
/browserstack-run.pid
/temp/
/docs/_site/

2 changes: 0 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ node_js:
- "14"
- "12"
- "10"
- "8"
- "6"
env:
- NPM_SCRIPT=test
matrix:
Expand Down
4 changes: 3 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,11 @@
],
"main": "qunit/qunit.js",
"engines": {
"node": ">=6"
"node": ">=10"
},
"dependencies": {
"commander": "2.12.2",
"js-reporters": "1.2.1",
"resolve": "1.9.0",
"node-watch": "0.6.4",
"minimatch": "3.0.4"
},
Expand Down
6 changes: 1 addition & 5 deletions src/cli/require-from-cwd.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
const resolve = require( "resolve" );

module.exports = function requireFromCWD( mod ) {

// TODO: Once Node 8+ is required, consider using native require.resolve().
const resolvedPath = resolve.sync( mod, { basedir: process.cwd() } );
const resolvedPath = require.resolve( mod, { paths: [ process.cwd() ] } );
return require( resolvedPath );
};
10 changes: 4 additions & 6 deletions src/cli/require-qunit.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,24 @@
const resolve = require( "resolve" );

// Depending on the exact usage, QUnit could be in one of several places, this
// function handles finding it.
module.exports = function requireQUnit() {
module.exports = function requireQUnit( resolve = require.resolve ) {
try {

// First we attempt to find QUnit relative to the current working directory.
const localQUnitPath = resolve.sync( "qunit", { basedir: process.cwd() } );
const localQUnitPath = resolve( "qunit", { paths: [ process.cwd() ] } );
delete require.cache[ localQUnitPath ];
return require( localQUnitPath );
} catch ( e ) {
try {

// Second, we use the globally installed QUnit
delete require.cache[ resolve.sync( "../../qunit/qunit" ) ];
delete require.cache[ resolve( "../../qunit/qunit" ) ];
// eslint-disable-next-line node/no-missing-require, node/no-unpublished-require
return require( "../../qunit/qunit" );
} catch ( e ) {
if ( e.code === "MODULE_NOT_FOUND" ) {

// Finally, we use the local development version of QUnit
delete require.cache[ resolve.sync( "../../dist/qunit" ) ];
delete require.cache[ resolve( "../../dist/qunit" ) ];
// eslint-disable-next-line node/no-missing-require, node/no-unpublished-require
return require( "../../dist/qunit" );
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 22 additions & 22 deletions test/cli/require-qunit-test.js
Original file line number Diff line number Diff line change
@@ -1,53 +1,53 @@
const proxyquire = require( "proxyquire" );
const resolveStub = {
sync( path ) {
return path;
}
const proxyquire = require( "proxyquire" ).noCallThru();
const path = require( "path" );
const resolveStub = ( path ) => {
return path;
};

QUnit.module( "requireQUnit", function() {
QUnit.module( "requireQUnit", function( hooks ) {
const cwd = process.cwd();

hooks.before( () => {
process.chdir( cwd );
} );
hooks.afterEach( () => {
process.chdir( cwd );
} );

QUnit.test( "finds QUnit in the current working directory", function( assert ) {
const localQUnit = {
"@noCallThru": true
};
const requireQUnit = proxyquire( "../../src/cli/require-qunit", {
"resolve": resolveStub,
"qunit": localQUnit
} );
const requireQUnit = require( "../../src/cli/require-qunit" );
process.chdir( path.join( __dirname, "./fixtures/require-from-cwd" ) );

assert.strictEqual( requireQUnit(), localQUnit );
assert.propEqual( requireQUnit(), { version: "from-cwd" } );
} );

QUnit.test( "finds globally installed QUnit", function( assert ) {
const globalQUnit = {
"@noCallThru": true
"version": "from-global"
};
const requireQUnit = proxyquire( "../../src/cli/require-qunit", {
"resolve": resolveStub,
"qunit": null,
"../../dist/qunit": null,
"../../qunit/qunit": globalQUnit
} );

assert.strictEqual( requireQUnit(), globalQUnit );
assert.strictEqual( requireQUnit( resolveStub ), globalQUnit );
} );

QUnit.test( "finds development mode QUnit", function( assert ) {
const devQUnit = {
"@noCallThru": true
"version": "from-dist"
};
const requireQUnit = proxyquire( "../../src/cli/require-qunit", {
"resolve": resolveStub,
"qunit": null,
"../../qunit/qunit": null,
"../../dist/qunit": devQUnit
} );

assert.strictEqual( requireQUnit(), devQUnit );
assert.strictEqual( requireQUnit( resolveStub ), devQUnit );
} );

QUnit.test( "throws error if none of the modules are found", function( assert ) {
const requireQUnit = proxyquire( "../../src/cli/require-qunit", {
"resolve": resolveStub,
"qunit": null,
"../../qunit/qunit": null,
"../../dist/qunit": null
Expand Down

0 comments on commit d7927a0

Please sign in to comment.