Skip to content

Commit

Permalink
Merge pull request #1034 from bertdeblock/migrate-test-suite-to-es-mo…
Browse files Browse the repository at this point in the history
…dules

Migrate test suite to ES modules
  • Loading branch information
bertdeblock authored Dec 18, 2024
2 parents 8f8be97 + 7ba588c commit bfd124b
Show file tree
Hide file tree
Showing 23 changed files with 279 additions and 218 deletions.
4 changes: 4 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ module.exports = {
{
env: { mocha: true },
files: ['test/**/*.js'],
parserOptions: { sourceType: 'module' },
rules: {
'n/no-extraneous-import': 'off',
},
},
],
parser: '@babel/eslint-parser',
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,17 @@
"@babel/core": "^7.26.0",
"@babel/eslint-parser": "^7.25.9",
"@release-it-plugins/lerna-changelog": "^7.0.0",
"chai": "^4.4.1",
"chai-as-promised": "^7.1.1",
"chai": "^5.1.2",
"chai-as-promised": "^8.0.1",
"codecov": "^3.8.3",
"concurrently": "^9.1.0",
"ember-cli": "~5.12.0",
"eslint": "^8.57.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-n": "^17.15.0",
"mocha": "^10.8.2",
"mocha": "^11.0.1",
"nyc": "^17.1.0",
"prettier": "^3.3.3",
"prettier": "^3.4.2",
"release-it": "^17.10.0",
"sinon": "^19.0.2",
"tmp-sync": "^1.1.0"
Expand Down
6 changes: 2 additions & 4 deletions test/commands/try-each-test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
'use strict';

const expect = require('chai').expect;
const TryEachCommand = require('../../lib/commands/try-each');
import { expect } from 'chai';
import TryEachCommand from '../../lib/commands/try-each.js';

const origTryEachTask = TryEachCommand._TryEachTask;
const origGetConfig = TryEachCommand._getConfig;
Expand Down
6 changes: 2 additions & 4 deletions test/commands/try-ember-test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
'use strict';

const expect = require('chai').expect;
const TryEmberCommand = require('../../lib/commands/try-ember');
import { expect } from 'chai';
import TryEmberCommand from '../../lib/commands/try-ember.js';

const origTryEachTask = TryEmberCommand._TryEachTask;
const origGetConfig = TryEmberCommand._getConfig;
Expand Down
6 changes: 2 additions & 4 deletions test/commands/try-one-test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
'use strict';

const expect = require('chai').expect;
const TryOneCommand = require('../../lib/commands/try-one');
import { expect } from 'chai';
import TryOneCommand from '../../lib/commands/try-one.js';

const origTryEachTask = TryOneCommand._TryEachTask;
const origGetConfig = TryOneCommand._getConfig;
Expand Down
21 changes: 10 additions & 11 deletions test/dependency-manager-adapters/npm-adapter-test.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
'use strict';

let expect = require('chai').expect;
let fs = require('fs-extra');
let path = require('path');
let tmp = require('tmp-sync');
let fixturePackage = require('../fixtures/package.json');
let NpmAdapter = require('../../lib/dependency-manager-adapters/npm');
let writeJSONFile = require('../helpers/write-json-file');
let assertFileContainsJSON = require('../helpers/assert-file-contains-json');
let generateMockRun = require('../helpers/generate-mock-run');
import { expect } from 'chai';
import fs from 'fs-extra';
import path from 'path';
import tmp from 'tmp-sync';
import NpmAdapter from '../../lib/dependency-manager-adapters/npm.js';
import writeJSONFile from '../helpers/write-json-file.js';
import assertFileContainsJSON from '../helpers/assert-file-contains-json.js';
import generateMockRun from '../helpers/generate-mock-run.js';

const fixturePackage = fs.readJsonSync('./test/fixtures/package.json');

let root = process.cwd();
let tmproot = path.join(root, 'tmp');
Expand Down
22 changes: 10 additions & 12 deletions test/dependency-manager-adapters/pnpm-adapter-test.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
'use strict';

let chai = require('chai');
let chaiAsPromised = require('chai-as-promised');
chai.use(chaiAsPromised);
let { expect } = chai;
let fs = require('fs-extra');
let path = require('path');
let tmp = require('tmp-sync');
const sinon = require('sinon');
let PnpmAdapter = require('../../lib/dependency-manager-adapters/pnpm');
let generateMockRun = require('../helpers/generate-mock-run');
import { expect, use } from 'chai';
import chaiAsPromised from 'chai-as-promised';
import fs from 'fs-extra';
import path from 'path';
import tmp from 'tmp-sync';
import sinon from 'sinon';
import PnpmAdapter from '../../lib/dependency-manager-adapters/pnpm.js';
import generateMockRun from '../helpers/generate-mock-run.js';

use(chaiAsPromised);

let root = process.cwd();
let tmproot = path.join(root, 'tmp');
Expand Down
21 changes: 10 additions & 11 deletions test/dependency-manager-adapters/workspace-adapter-test.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
'use strict';

let expect = require('chai').expect;
let fs = require('fs-extra');
let path = require('path');
let tmp = require('tmp-sync');
let fixtureWorkspaces = require('../fixtures/package-with-workspaces.json');
let WorkspaceAdapter = require('../../lib/dependency-manager-adapters/workspace');
let writeJSONFile = require('../helpers/write-json-file');
let assertFileContainsJSON = require('../helpers/assert-file-contains-json');
let generateMockRun = require('../helpers/generate-mock-run');
import { expect } from 'chai';
import fs from 'fs-extra';
import path from 'path';
import tmp from 'tmp-sync';
import WorkspaceAdapter from '../../lib/dependency-manager-adapters/workspace.js';
import writeJSONFile from '../helpers/write-json-file.js';
import assertFileContainsJSON from '../helpers/assert-file-contains-json.js';
import generateMockRun from '../helpers/generate-mock-run.js';

const fixtureWorkspaces = fs.readJsonSync('./test/fixtures/package-with-workspaces.json');

let root = process.cwd();
let tmproot = path.join(root, 'tmp');
Expand Down
21 changes: 10 additions & 11 deletions test/dependency-manager-adapters/yarn-adapter-test.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
'use strict';

let expect = require('chai').expect;
let fs = require('fs-extra');
let path = require('path');
let tmp = require('tmp-sync');
let fixturePackage = require('../fixtures/package.json');
let YarnAdapter = require('../../lib/dependency-manager-adapters/yarn');
let writeJSONFile = require('../helpers/write-json-file');
let assertFileContainsJSON = require('../helpers/assert-file-contains-json');
let generateMockRun = require('../helpers/generate-mock-run');
import { expect } from 'chai';
import fs from 'fs-extra';
import path from 'path';
import tmp from 'tmp-sync';
import YarnAdapter from '../../lib/dependency-manager-adapters/yarn.js';
import writeJSONFile from '../helpers/write-json-file.js';
import assertFileContainsJSON from '../helpers/assert-file-contains-json.js';
import generateMockRun from '../helpers/generate-mock-run.js';

const fixturePackage = fs.readJsonSync('./test/fixtures/package.json');

let root = process.cwd();
let tmproot = path.join(root, 'tmp');
Expand Down
12 changes: 5 additions & 7 deletions test/helpers/assert-file-contains-json.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
'use strict';
import { expect } from 'chai';
import fs from 'fs-extra';
import path from 'path';

let expect = require('chai').expect;
let fs = require('fs-extra');
let path = require('path');

module.exports = function assertFileContainsJSON(filePath, expectedObj) {
export default function assertFileContainsJSON(filePath, expectedObj) {
return assertFileContains(filePath, JSON.stringify(expectedObj, null, 2));
};
}

function assertFileContains(filePath, expectedContents) {
let regex = new RegExp(`${escapeForRegex(expectedContents)}($|\\W)`, 'gm');
Expand Down
8 changes: 3 additions & 5 deletions test/helpers/generate-mock-run.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
'use strict';
import { _originalRunFunction } from '../../lib/utils/run.js';

const { _originalRunFunction } = require('../../lib/utils/run');

module.exports = function generateMockRun() {
export default function generateMockRun() {
let mockedRuns = [];
let options = { allowPassthrough: true };
if (typeof arguments[0] === 'string') {
Expand All @@ -28,7 +26,7 @@ module.exports = function generateMockRun() {
);
}
};
};
}

function isCommandMocked(mockedRun, actualCommand, actualArgs) {
let mockedRunParts = mockedRun.command.split(' ');
Expand Down
6 changes: 2 additions & 4 deletions test/helpers/stub-dependency-manager-adapter.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
'use strict';

module.exports = class {
export default class {
setup() {
return Promise.resolve();
}
Expand All @@ -18,4 +16,4 @@ module.exports = class {
cleanup() {
return Promise.resolve();
}
};
}
8 changes: 3 additions & 5 deletions test/helpers/write-json-file.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
'use strict';
import fs from 'fs-extra';

const fs = require('fs-extra');

module.exports = function writeJSONFile(filename, contents) {
export default function writeJSONFile(filename, contents) {
fs.writeFileSync(filename, JSON.stringify(contents, null, 2));
};
}
6 changes: 6 additions & 0 deletions test/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"description": "This `package.json` file solely exists to use ES modules in the test suite.",
"name": "test",
"private": true,
"type": "module"
}
13 changes: 6 additions & 7 deletions test/tasks/reset-test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
'use strict';
import tmp from 'tmp-sync';
import path from 'path';
import fs from 'fs-extra';
import writeJSONFile from '../helpers/write-json-file.js';
import ResetTask from '../../lib/tasks/reset.js';

const tmp = require('tmp-sync');
const path = require('path');
const fs = require('fs-extra');
const fixturePackageJson = require('../fixtures/package.json');
const writeJSONFile = require('../helpers/write-json-file');
const fixturePackageJson = fs.readJsonSync('./test/fixtures/package.json');

const root = process.cwd();
const tmproot = path.join(root, 'tmp');
Expand Down Expand Up @@ -36,7 +36,6 @@ describe('reset', () => {
],
};

let ResetTask = require('../../lib/tasks/reset');
let resetTask = new ResetTask({
project: { root: tmpdir },
config,
Expand Down
Loading

0 comments on commit bfd124b

Please sign in to comment.