Skip to content

Commit

Permalink
fix legacy mocha tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Gaurav0 committed May 14, 2023
1 parent 961e776 commit 21e63a7
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 35 deletions.
13 changes: 9 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,15 @@
"type": "git",
"url": "[email protected]:ember-fastboot/ember-cli-fastboot.git"
},
"workspaces": [
"packages/*",
"test-packages/*"
],
"workspaces": {
"packages": [
"packages/*",
"test-packages/*"
],
"nohoist": [
"**/ember-cli-addon-tests"
]
},
"scripts": {
"test": "npm-run-all test:*",
"test:ember-cli-fastboot": "yarn workspace ember-cli-fastboot test:ember",
Expand Down
10 changes: 10 additions & 0 deletions packages/ember-cli-fastboot/fix-node-modules.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const __dirname = path.dirname(fileURLToPath(import.meta.url));

const packagesDir = path.resolve(__dirname, '../../packages');
const nodeModulesDir = path.resolve(__dirname, 'node_modules');
const precookedDir = path.resolve(__dirname, 'tmp', 'precooked_node_modules');

// eslint-disable-next-line no-undef
const shouldRestore = process.argv[2];
Expand All @@ -29,18 +30,27 @@ Options:
function run(shouldRestore) {
['fastboot', 'fastboot-express-middleware'].forEach((packageName) => {
const nodeModulesPackageDir = path.join(nodeModulesDir, packageName);
const precookedPackageDir = path.join(precookedDir, packageName);
const workspacesPackageDir = path.resolve(packagesDir, packageName);
if (fs.existsSync(nodeModulesPackageDir)) {
console.log(chalk.blue(`remove ${nodeModulesPackageDir}`));
fs.removeSync(nodeModulesPackageDir);
}
if (fs.existsSync(precookedPackageDir)) {
console.log(chalk.blue(`remove ${precookedPackageDir}`));
fs.removeSync(precookedPackageDir);
}
if (!shouldRestore) {
console.log(
chalk.green(
`symlink ${nodeModulesPackageDir} -> ${workspacesPackageDir}`
)
);
fs.symlinkSync(workspacesPackageDir, nodeModulesPackageDir, 'dir');
console.log(
chalk.green(`symlink ${precookedPackageDir} -> ${workspacesPackageDir}`)
);
fs.symlinkSync(workspacesPackageDir, precookedPackageDir, 'dir');
}
});
}
10 changes: 7 additions & 3 deletions packages/ember-cli-fastboot/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
"release": "release-it",
"lint:js:fix": "eslint . --fix",
"start": "ember serve",
"test": "npm-run-all lint test:*",
"test:mocha": "node fix-node-modules.mjs && mocha && node fix-node-modules.mjs -r",
"pretest:precook": "node node_modules/ember-cli-addon-tests/scripts/precook-node-modules.js",
"test": "npm-run-all lint pretest:* test:*",
"test:mocha": "node fix-node-modules.mjs && mocha",
"test:ember": "ember test",
"test:precook": "node node_modules/ember-cli-addon-tests/scripts/precook-node-modules.js",
"test:ember-compatibility": "ember try:each"
},
"dependencies": {
Expand All @@ -45,9 +45,13 @@
"fs-extra": "^10.0.0",
"json-stable-stringify": "^1.0.1",
"md5-hex": "^3.0.1",
"node-fetch": "^2.6.7",
"recast": "^0.19.1",
"silent-error": "^1.1.1"
},
"fastbootDependencies": [
"node-fetch"
],
"devDependencies": {
"@ember/optional-features": "^2.0.0",
"@ember/test-helpers": "^2.6.0",
Expand Down
6 changes: 3 additions & 3 deletions packages/ember-cli-fastboot/test/fastboot-config-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ describe('FastBoot config', function () {

return app
.create('fastboot-config', {
emberVersion: 'latest',
emberDataVersion: 'latest',
emberVersion: '~3.28.12',
emberDataVersion: '~3.28.12',
})
.then(function () {
app.editPackageJSON((pkg) => {
delete pkg.devDependencies['ember-fetch'];
delete pkg.devDependencies['ember-welcome-page'];
// needed because @ember-data/store does `FastBoot.require('crypto')`
pkg.fastbootDependencies = ['crypto'];
pkg.fastbootDependencies = ['node-fetch', 'crypto'];
});
return app.run('npm', 'install');
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ describe('FastBootLocation Configuration', function () {

return app
.create('fastboot-location-config', {
emberVersion: 'latest',
emberDataVersion: 'latest',
emberVersion: '~3.28.12',
emberDataVersion: '~3.28.12',
})
.then(function () {
app.editPackageJSON((pkg) => {
delete pkg.devDependencies['ember-fetch'];
delete pkg.devDependencies['ember-welcome-page'];
// needed because @ember-data/store does `FastBoot.require('crypto')`
pkg.fastbootDependencies = ['crypto'];
pkg.fastbootDependencies = ['node-fetch', 'crypto'];
});
return app.run('npm', 'install');
})
Expand Down
6 changes: 3 additions & 3 deletions packages/ember-cli-fastboot/test/fastboot-location-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ describe('FastBootLocation', function () {

return app
.create('fastboot-location', {
emberVersion: 'latest',
emberDataVersion: 'latest',
emberVersion: '~3.28.12',
emberDataVersion: '~3.28.12',
})
.then(function () {
app.editPackageJSON((pkg) => {
delete pkg.devDependencies['ember-fetch'];
delete pkg.devDependencies['ember-welcome-page'];
// needed because @ember-data/store does `FastBoot.require('crypto')`
pkg.fastbootDependencies = ['crypto'];
pkg.fastbootDependencies = ['node-fetch', 'crypto'];
});
return app.run('npm', 'install');
})
Expand Down
6 changes: 3 additions & 3 deletions packages/ember-cli-fastboot/test/package-json-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ describe('generating package.json', function () {
before(function () {
return customApp
.create('customized-outputpaths', {
emberVersion: 'latest',
emberDataVersion: 'latest',
emberVersion: '~3.28.12',
emberDataVersion: '~3.28.12',
})
.then(function () {
customApp.editPackageJSON((pkg) => {
delete pkg.devDependencies['ember-fetch'];
delete pkg.devDependencies['ember-welcome-page'];
// needed because @ember-data/store does `FastBoot.require('crypto')`
pkg.fastbootDependencies = ['crypto'];
pkg.fastbootDependencies = ['node-fetch', 'crypto'];
});
return customApp.run('npm', 'install');
})
Expand Down
34 changes: 21 additions & 13 deletions packages/ember-cli-fastboot/test/request-details-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,36 @@ const RSVP = require('rsvp');
const AddonTestApp = require('ember-cli-addon-tests').AddonTestApp;
const request = RSVP.denodeify(require('request'));

function injectMiddlewareAddon(app) {
async function injectMiddlewareAddon(app) {
app.editPackageJSON(function (pkg) {
pkg.devDependencies['body-parser'] =
process.env.npm_package_devDependencies_body_parser;
pkg.dependencies = pkg.dependencies || {};
pkg.dependencies['fastboot'] = `file:${path.resolve(
__dirname,
'../../fastboot'
)}`;
pkg.dependencies['fastboot-express-middleware'] = `file:${path.resolve(
__dirname,
'../../fastboot-express-middleware'
)}`;
pkg['ember-addon'] = {
paths: ['lib/post-middleware'],
};
delete pkg.devDependencies['ember-fetch'];
delete pkg.devDependencies['ember-welcome-page'];
// needed because @ember-data/store does `FastBoot.require('crypto')`
pkg.fastbootDependencies = ['crypto'];
pkg.fastbootDependencies = ['node-fetch', 'crypto'];
});
await app.run('npm', 'install', '--no-package-lock');
await app.run(
'ln',
'-s',
path.resolve(__dirname, '../../fastboot'),
path.resolve(app.path, 'node_modules/fastboot')
);
await app.run(
'ln',
'-s',
path.resolve(__dirname, '../../fastboot-express-middleware'),
path.resolve(app.path, 'node_modules/fastboot-express-middleware')
);
app.editPackageJSON(function (pkg) {
pkg.dependencies['fastboot'] = '*';
pkg.dependencies['fastboot-express-middleware'] = '*';
});
return app.run('npm', 'install');
}

describe('request details', function () {
Expand All @@ -41,8 +49,8 @@ describe('request details', function () {

return app
.create('request', {
emberVersion: 'latest',
emberDataVersion: 'latest',
emberVersion: '~3.28.12',
emberDataVersion: '~3.28.12',
})
.then(() => injectMiddlewareAddon(app))
.then(function () {
Expand Down
6 changes: 3 additions & 3 deletions packages/ember-cli-fastboot/test/root-url-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ describe('rootUrl acceptance', function () {

return app
.create('root-url', {
emberVersion: 'latest',
emberDataVersion: 'latest',
emberVersion: '~3.28.12',
emberDataVersion: '~3.28.12',
})
.then(function () {
app.editPackageJSON((pkg) => {
delete pkg.devDependencies['ember-fetch'];
delete pkg.devDependencies['ember-welcome-page'];
// needed because @ember-data/store does `FastBoot.require('crypto')`
pkg.fastbootDependencies = ['crypto'];
pkg.fastbootDependencies = ['node-fetch', 'crypto'];
});
return app.run('npm', 'install');
})
Expand Down

0 comments on commit 21e63a7

Please sign in to comment.