install-ember-testem 0.1.4 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/blueprints/v2-addon/babel.test.config.mjs +35 -0
- package/dist/src/blueprints/v2-addon/tests/app.__js__ +15 -0
- package/dist/src/blueprints/v2-addon/tests/helpers/index.js +25 -0
- package/dist/src/blueprints/v2-addon/tests/helpers/index.ts +32 -0
- package/dist/src/blueprints/v2-addon/tests/index.html +27 -0
- package/dist/src/blueprints/v2-addon/tests/integration/__gitkeep__ +0 -0
- package/dist/src/blueprints/v2-addon/tests/test-helper.__js__ +20 -0
- package/dist/src/blueprints/v2-addon/vite.test.config.__mjs__ +24 -0
- package/dist/src/blueprints/v2-app/vite.test.config.__mjs__ +11 -0
- package/dist/src/index.js +7 -1
- package/dist/src/steps/create-options.js +13 -1
- package/dist/src/steps/create-tests-folder.js +52 -0
- package/dist/src/steps/create-vite-test-config.js +52 -0
- package/dist/src/steps/index.js +3 -0
- package/dist/src/steps/update-package-json/update-dependencies.js +23 -6
- package/dist/src/steps/update-package-json/update-scripts.js +7 -2
- package/dist/src/steps/update-testem-config/convert-to-esm.js +41 -0
- package/dist/src/steps/update-testem-config/create-config.js +32 -0
- package/dist/src/steps/update-testem-config/index.js +2 -0
- package/dist/src/steps/update-testem-config.js +24 -0
- package/dist/src/utils/blueprints/get-version.js +18 -0
- package/dist/src/utils/blueprints.js +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { buildMacros } from '@embroider/macros/babel';
|
|
2
|
+
|
|
3
|
+
const macros = buildMacros();
|
|
4
|
+
|
|
5
|
+
export default {
|
|
6
|
+
generatorOpts: {
|
|
7
|
+
compact: false,
|
|
8
|
+
},
|
|
9
|
+
plugins: [
|
|
10
|
+
[
|
|
11
|
+
'@babel/plugin-transform-typescript',
|
|
12
|
+
{
|
|
13
|
+
allExtensions: true,
|
|
14
|
+
allowDeclareFields: true,
|
|
15
|
+
onlyRemoveTypeImports: true,
|
|
16
|
+
},
|
|
17
|
+
],
|
|
18
|
+
'@embroider/addon-dev/template-colocation-plugin',
|
|
19
|
+
[
|
|
20
|
+
'babel-plugin-ember-template-compilation',
|
|
21
|
+
{
|
|
22
|
+
transforms: [...macros.templateMacros],
|
|
23
|
+
},
|
|
24
|
+
],
|
|
25
|
+
[
|
|
26
|
+
'module:decorator-transforms',
|
|
27
|
+
{
|
|
28
|
+
runtime: {
|
|
29
|
+
import: 'decorator-transforms/runtime-esm',
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
],
|
|
33
|
+
...macros.babelMacros,
|
|
34
|
+
],
|
|
35
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import EmberRouter from '@ember/routing/router';
|
|
2
|
+
import Application from 'ember-strict-application-resolver';
|
|
3
|
+
|
|
4
|
+
class Router extends EmberRouter {
|
|
5
|
+
location = 'none';
|
|
6
|
+
rootURL = '/';
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
Router.map(function () {});
|
|
10
|
+
|
|
11
|
+
export default class App extends Application {
|
|
12
|
+
modules = {
|
|
13
|
+
'./router': Router,
|
|
14
|
+
};
|
|
15
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import {
|
|
2
|
+
setupApplicationTest as upstreamSetupApplicationTest,
|
|
3
|
+
setupRenderingTest as upstreamSetupRenderingTest,
|
|
4
|
+
setupTest as upstreamSetupTest,
|
|
5
|
+
} from 'ember-qunit';
|
|
6
|
+
|
|
7
|
+
function setupApplicationTest(hooks, options) {
|
|
8
|
+
upstreamSetupApplicationTest(hooks, options);
|
|
9
|
+
|
|
10
|
+
// Additional setup for application tests can be done here.
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function setupRenderingTest(hooks, options) {
|
|
14
|
+
upstreamSetupRenderingTest(hooks, options);
|
|
15
|
+
|
|
16
|
+
// Additional setup for rendering tests can be done here.
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function setupTest(hooks, options) {
|
|
20
|
+
upstreamSetupTest(hooks, options);
|
|
21
|
+
|
|
22
|
+
// Additional setup for unit tests can be done here.
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export { setupApplicationTest, setupRenderingTest, setupTest };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import {
|
|
2
|
+
setupApplicationTest as upstreamSetupApplicationTest,
|
|
3
|
+
setupRenderingTest as upstreamSetupRenderingTest,
|
|
4
|
+
setupTest as upstreamSetupTest,
|
|
5
|
+
type SetupTestOptions,
|
|
6
|
+
} from 'ember-qunit';
|
|
7
|
+
|
|
8
|
+
function setupApplicationTest(
|
|
9
|
+
hooks: NestedHooks,
|
|
10
|
+
options?: SetupTestOptions,
|
|
11
|
+
): void {
|
|
12
|
+
upstreamSetupApplicationTest(hooks, options);
|
|
13
|
+
|
|
14
|
+
// Additional setup for application tests can be done here.
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function setupRenderingTest(
|
|
18
|
+
hooks: NestedHooks,
|
|
19
|
+
options?: SetupTestOptions,
|
|
20
|
+
): void {
|
|
21
|
+
upstreamSetupRenderingTest(hooks, options);
|
|
22
|
+
|
|
23
|
+
// Additional setup for rendering tests can be done here.
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function setupTest(hooks: NestedHooks, options?: SetupTestOptions): void {
|
|
27
|
+
upstreamSetupTest(hooks, options);
|
|
28
|
+
|
|
29
|
+
// Additional setup for unit tests can be done here.
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export { setupApplicationTest, setupRenderingTest, setupTest };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8" />
|
|
5
|
+
<title>Tests</title>
|
|
6
|
+
<meta name="description" content="">
|
|
7
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
8
|
+
</head>
|
|
9
|
+
<body>
|
|
10
|
+
<div id="qunit"></div>
|
|
11
|
+
<div id="qunit-fixture">
|
|
12
|
+
<div id="ember-testing-container">
|
|
13
|
+
<div id="ember-testing"></div>
|
|
14
|
+
</div>
|
|
15
|
+
</div>
|
|
16
|
+
|
|
17
|
+
<script src="/testem.js" integrity="" data-embroider-ignore></script>
|
|
18
|
+
|
|
19
|
+
<script type="module">import 'ember-testing';</script>
|
|
20
|
+
<script type="module">
|
|
21
|
+
import { start } from './test-helper';
|
|
22
|
+
import.meta.glob('./**/*.{gjs,gts,js,ts}', { eager: true });
|
|
23
|
+
|
|
24
|
+
start();
|
|
25
|
+
</script>
|
|
26
|
+
</body>
|
|
27
|
+
</html>
|
|
File without changes
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { setApplication } from '@ember/test-helpers';
|
|
2
|
+
import { setTesting } from '@embroider/macros';
|
|
3
|
+
import { setupEmberOnerrorValidation, start as qunitStart } from 'ember-qunit';
|
|
4
|
+
import QUnit from 'qunit';
|
|
5
|
+
import { setup } from 'qunit-dom';
|
|
6
|
+
|
|
7
|
+
import Application from './app';
|
|
8
|
+
|
|
9
|
+
export function start() {
|
|
10
|
+
setTesting(true);
|
|
11
|
+
setApplication(
|
|
12
|
+
Application.create({
|
|
13
|
+
autoboot: false,
|
|
14
|
+
rootElement: '#ember-testing',
|
|
15
|
+
}),
|
|
16
|
+
);
|
|
17
|
+
setup(QUnit.assert);
|
|
18
|
+
setupEmberOnerrorValidation();
|
|
19
|
+
qunitStart();
|
|
20
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { ember, extensions } from '@embroider/vite';
|
|
2
|
+
import { babel } from '@rollup/plugin-babel';
|
|
3
|
+
import { defineConfig } from 'vite';
|
|
4
|
+
|
|
5
|
+
export default defineConfig({
|
|
6
|
+
build: {
|
|
7
|
+
minify: false,
|
|
8
|
+
rollupOptions: {
|
|
9
|
+
input: {
|
|
10
|
+
tests: 'tests/index.html',
|
|
11
|
+
},
|
|
12
|
+
},
|
|
13
|
+
sourcemap: true,
|
|
14
|
+
},
|
|
15
|
+
plugins: [
|
|
16
|
+
ember(),
|
|
17
|
+
babel({
|
|
18
|
+
babelHelpers: 'inline',
|
|
19
|
+
configFile: './babel.test.config.mjs',
|
|
20
|
+
extensions,
|
|
21
|
+
parallel: true,
|
|
22
|
+
}),
|
|
23
|
+
],
|
|
24
|
+
});
|
package/dist/src/index.js
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
|
-
import { createOptions, updatePackageJson } from './steps/index.js';
|
|
1
|
+
import { createOptions, createTestsFolder, createViteTestConfig, updatePackageJson, updateTestemConfig, } from './steps/index.js';
|
|
2
2
|
export function runCodemod(codemodOptions) {
|
|
3
3
|
const options = createOptions(codemodOptions);
|
|
4
|
+
if (options.project.hasEmberTestem) {
|
|
5
|
+
return;
|
|
6
|
+
}
|
|
7
|
+
updateTestemConfig(options);
|
|
8
|
+
createViteTestConfig(options);
|
|
9
|
+
createTestsFolder(options);
|
|
4
10
|
updatePackageJson(options);
|
|
5
11
|
}
|
|
@@ -1,4 +1,15 @@
|
|
|
1
|
-
import { getPackageType, readPackageJson } from '@codemod-utils/package-json';
|
|
1
|
+
import { getPackageType, readPackageJson, } from '@codemod-utils/package-json';
|
|
2
|
+
function analyzeProject(packageJson) {
|
|
3
|
+
const { dependencies, devDependencies } = packageJson;
|
|
4
|
+
const projectDependencies = new Map([
|
|
5
|
+
...Object.entries(dependencies ?? {}),
|
|
6
|
+
...Object.entries(devDependencies ?? {}),
|
|
7
|
+
]);
|
|
8
|
+
return {
|
|
9
|
+
hasEmberTestem: projectDependencies.has('ember-testem'),
|
|
10
|
+
hasTypeScript: projectDependencies.has('typescript'),
|
|
11
|
+
};
|
|
12
|
+
}
|
|
2
13
|
export function createOptions(codemodOptions) {
|
|
3
14
|
const { projectRoot } = codemodOptions;
|
|
4
15
|
const packageJson = readPackageJson({ projectRoot });
|
|
@@ -8,6 +19,7 @@ export function createOptions(codemodOptions) {
|
|
|
8
19
|
}
|
|
9
20
|
return {
|
|
10
21
|
packageType,
|
|
22
|
+
project: analyzeProject(packageJson),
|
|
11
23
|
projectRoot,
|
|
12
24
|
};
|
|
13
25
|
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { processTemplate } from '@codemod-utils/blueprints';
|
|
4
|
+
import { createFiles, findFiles } from '@codemod-utils/files';
|
|
5
|
+
import { blueprintsRoot } from '../utils/blueprints.js';
|
|
6
|
+
function getFilesToSkip(data) {
|
|
7
|
+
const { hasTypeScript } = data;
|
|
8
|
+
const files = new Set([
|
|
9
|
+
'babel.test.config.mjs',
|
|
10
|
+
'vite.test.config.__mjs__',
|
|
11
|
+
]);
|
|
12
|
+
if (hasTypeScript) {
|
|
13
|
+
files.add('tests/helpers/index.js');
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
files.add('tests/helpers/index.ts');
|
|
17
|
+
}
|
|
18
|
+
return Array.from(files);
|
|
19
|
+
}
|
|
20
|
+
function resolveBlueprintFilePath(blueprintFilePath, data) {
|
|
21
|
+
const { hasTypeScript } = data;
|
|
22
|
+
return blueprintFilePath
|
|
23
|
+
.replace('__gitkeep__', '.gitkeep')
|
|
24
|
+
.replace('__js__', hasTypeScript ? 'ts' : 'js')
|
|
25
|
+
.replace('__mjs__', hasTypeScript ? 'mts' : 'mjs');
|
|
26
|
+
}
|
|
27
|
+
export function createTestsFolder(options) {
|
|
28
|
+
const { packageType, projectRoot } = options;
|
|
29
|
+
if (packageType !== 'v2-addon') {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
const hasTestsFolder = findFiles('tests/**/*', { projectRoot }).length > 0;
|
|
33
|
+
if (hasTestsFolder) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
const data = {
|
|
37
|
+
hasTypeScript: false,
|
|
38
|
+
};
|
|
39
|
+
const filesToSkip = getFilesToSkip(data);
|
|
40
|
+
const cwd = join(blueprintsRoot, packageType);
|
|
41
|
+
const blueprintFilePaths = findFiles('**/*', {
|
|
42
|
+
ignoreList: filesToSkip,
|
|
43
|
+
projectRoot: cwd,
|
|
44
|
+
});
|
|
45
|
+
const fileMap = new Map(blueprintFilePaths.map((blueprintFilePath) => {
|
|
46
|
+
const filePath = resolveBlueprintFilePath(blueprintFilePath, data);
|
|
47
|
+
const blueprintFile = readFileSync(join(cwd, blueprintFilePath), 'utf8');
|
|
48
|
+
const file = processTemplate(blueprintFile, { data });
|
|
49
|
+
return [filePath, file];
|
|
50
|
+
}));
|
|
51
|
+
createFiles(fileMap, { projectRoot });
|
|
52
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { processTemplate } from '@codemod-utils/blueprints';
|
|
4
|
+
import { createFiles, findFiles } from '@codemod-utils/files';
|
|
5
|
+
import { blueprintsRoot } from '../utils/blueprints.js';
|
|
6
|
+
function findUserConfig(projectRoot) {
|
|
7
|
+
// https://github.com/vitejs/vite/blob/v8.3.5/packages/vite/src/node/constants.ts
|
|
8
|
+
const filePaths = findFiles('vite.config.{js,mjs,mts,ts}', {
|
|
9
|
+
projectRoot,
|
|
10
|
+
});
|
|
11
|
+
if (filePaths.length === 1) {
|
|
12
|
+
return filePaths[0];
|
|
13
|
+
}
|
|
14
|
+
return undefined;
|
|
15
|
+
}
|
|
16
|
+
function resolveBlueprintFilePath(blueprintFilePath, data) {
|
|
17
|
+
const { hasTypeScript } = data;
|
|
18
|
+
return blueprintFilePath.replace('__mjs__', hasTypeScript ? 'mts' : 'mjs');
|
|
19
|
+
}
|
|
20
|
+
export function createViteTestConfig(options) {
|
|
21
|
+
const { packageType, projectRoot } = options;
|
|
22
|
+
if (packageType === 'v1-addon' || packageType === 'v1-app') {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
let data;
|
|
26
|
+
if (packageType === 'v2-addon') {
|
|
27
|
+
data = {
|
|
28
|
+
hasTypeScript: false,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
const filePath = findUserConfig(projectRoot);
|
|
33
|
+
if (filePath === undefined) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
data = {
|
|
37
|
+
hasTypeScript: filePath.endsWith('.mts') || filePath.endsWith('.ts'),
|
|
38
|
+
viteConfigFilePath: filePath,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
const cwd = join(blueprintsRoot, packageType);
|
|
42
|
+
const blueprintFilePaths = findFiles(['babel.test.config.mjs', 'vite.test.config.__mjs__'], {
|
|
43
|
+
projectRoot: cwd,
|
|
44
|
+
});
|
|
45
|
+
const fileMap = new Map(blueprintFilePaths.map((blueprintFilePath) => {
|
|
46
|
+
const filePath = resolveBlueprintFilePath(blueprintFilePath, data);
|
|
47
|
+
const blueprintFile = readFileSync(join(cwd, blueprintFilePath), 'utf8');
|
|
48
|
+
const file = processTemplate(blueprintFile, { data });
|
|
49
|
+
return [filePath, file];
|
|
50
|
+
}));
|
|
51
|
+
createFiles(fileMap, { projectRoot });
|
|
52
|
+
}
|
package/dist/src/steps/index.js
CHANGED
|
@@ -1,12 +1,29 @@
|
|
|
1
1
|
import { convertToMap, convertToObject, } from '@codemod-utils/package-json';
|
|
2
|
-
|
|
3
|
-
'ember-testem': '^0.5.1',
|
|
4
|
-
};
|
|
2
|
+
import { getLatestVersion } from '../../utils/blueprints.js';
|
|
5
3
|
export function updateDependencies(packageJson, options) {
|
|
4
|
+
const { packageType, project } = options;
|
|
6
5
|
const devDependencies = convertToMap(packageJson['devDependencies']);
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
const packagesToDelete = new Set(['testem']);
|
|
7
|
+
packagesToDelete.forEach((packageName) => {
|
|
8
|
+
devDependencies.delete(packageName);
|
|
9
|
+
});
|
|
10
|
+
const packagesToInstall = new Set(['ember-testem']);
|
|
11
|
+
if (packageType === 'v2-addon') {
|
|
12
|
+
packagesToInstall.add('@ember/test-helpers');
|
|
13
|
+
packagesToInstall.add('@embroider/macros');
|
|
14
|
+
packagesToInstall.add('@embroider/vite');
|
|
15
|
+
packagesToInstall.add('ember-qunit');
|
|
16
|
+
packagesToInstall.add('ember-strict-application-resolver');
|
|
17
|
+
packagesToInstall.add('qunit');
|
|
18
|
+
packagesToInstall.add('qunit-dom');
|
|
19
|
+
packagesToInstall.add('vite');
|
|
20
|
+
if (project.hasTypeScript) {
|
|
21
|
+
packagesToInstall.add('@types/qunit');
|
|
22
|
+
}
|
|
10
23
|
}
|
|
24
|
+
packagesToInstall.forEach((packageName) => {
|
|
25
|
+
const version = getLatestVersion(packageName);
|
|
26
|
+
devDependencies.set(packageName, version);
|
|
27
|
+
});
|
|
11
28
|
packageJson['devDependencies'] = convertToObject(devDependencies);
|
|
12
29
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { findFiles } from '@codemod-utils/files';
|
|
1
2
|
import { convertToMap, convertToObject, } from '@codemod-utils/package-json';
|
|
2
3
|
const mapArgumentNames = new Map([
|
|
3
4
|
['-f', '-f'],
|
|
@@ -34,12 +35,13 @@ function getTestArguments(testScript) {
|
|
|
34
35
|
return ' ' + testArgumentsNew.join(' ');
|
|
35
36
|
}
|
|
36
37
|
export function updateScripts(packageJson, options) {
|
|
38
|
+
const { packageType, projectRoot } = options;
|
|
37
39
|
const scripts = convertToMap(packageJson['scripts']);
|
|
38
40
|
const testScript = (scripts.get('test') ?? '');
|
|
39
41
|
if (testScript.includes('ember-test')) {
|
|
40
42
|
return;
|
|
41
43
|
}
|
|
42
|
-
switch (
|
|
44
|
+
switch (packageType) {
|
|
43
45
|
case 'v1-addon':
|
|
44
46
|
case 'v1-app': {
|
|
45
47
|
scripts.set('build:test', 'ember build --environment test');
|
|
@@ -47,7 +49,10 @@ export function updateScripts(packageJson, options) {
|
|
|
47
49
|
}
|
|
48
50
|
case 'v2-addon':
|
|
49
51
|
case 'v2-app': {
|
|
50
|
-
|
|
52
|
+
const viteTestConfigFilePath = findFiles('vite.test.config.{mjs,mts}', {
|
|
53
|
+
projectRoot,
|
|
54
|
+
})[0];
|
|
55
|
+
scripts.set('build:test', `NODE_ENV=development vite build --config ${viteTestConfigFilePath} --mode development`);
|
|
51
56
|
break;
|
|
52
57
|
}
|
|
53
58
|
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { readFileSync, rmSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { EOL } from 'node:os';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import { AST } from '@codemod-utils/ast-javascript';
|
|
5
|
+
function createDefaultExport(file) {
|
|
6
|
+
let properties;
|
|
7
|
+
AST.traverse(file, {
|
|
8
|
+
visitAssignmentExpression(path) {
|
|
9
|
+
if (path.node.left.type !== 'MemberExpression' ||
|
|
10
|
+
path.node.left.object.type !== 'Identifier' ||
|
|
11
|
+
path.node.left.object.name !== 'module' ||
|
|
12
|
+
path.node.left.property.type !== 'Identifier' ||
|
|
13
|
+
path.node.left.property.name !== 'exports') {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
if (path.node.right.type !== 'ObjectExpression') {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
properties = path.node.right.properties;
|
|
20
|
+
return false;
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
if (properties === undefined) {
|
|
24
|
+
return file;
|
|
25
|
+
}
|
|
26
|
+
const newFile = [`export default {};`, ``].join(EOL);
|
|
27
|
+
const ast = AST.traverse(newFile, {
|
|
28
|
+
visitExportDefaultDeclaration(path) {
|
|
29
|
+
path.node.declaration = AST.builders.objectExpression(properties);
|
|
30
|
+
return false;
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
return AST.print(ast);
|
|
34
|
+
}
|
|
35
|
+
export function convertToEsm(filePath, options) {
|
|
36
|
+
const { projectRoot } = options;
|
|
37
|
+
let file = readFileSync(join(projectRoot, filePath), 'utf8');
|
|
38
|
+
file = createDefaultExport(file);
|
|
39
|
+
writeFileSync(join(projectRoot, 'testem.mjs'), file, 'utf8');
|
|
40
|
+
rmSync(join(projectRoot, filePath));
|
|
41
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { writeFileSync } from 'node:fs';
|
|
2
|
+
import { EOL } from 'node:os';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
export function createConfig(options) {
|
|
5
|
+
const { project, projectRoot } = options;
|
|
6
|
+
const filePath = project.hasTypeScript ? 'testem.mts' : 'testem.mjs';
|
|
7
|
+
const file = [
|
|
8
|
+
`export default {`,
|
|
9
|
+
` browser_args: {`,
|
|
10
|
+
` Chrome: {`,
|
|
11
|
+
` ci: [`,
|
|
12
|
+
` // --no-sandbox is needed when running Chrome inside a container`,
|
|
13
|
+
` process.env['CI'] ? '--no-sandbox' : null,`,
|
|
14
|
+
` '--headless',`,
|
|
15
|
+
` '--disable-dev-shm-usage',`,
|
|
16
|
+
` '--disable-software-rasterizer',`,
|
|
17
|
+
` '--mute-audio',`,
|
|
18
|
+
` '--remote-debugging-port=0',`,
|
|
19
|
+
` '--window-size=1440,900',`,
|
|
20
|
+
` ].filter(Boolean),`,
|
|
21
|
+
` },`,
|
|
22
|
+
` },`,
|
|
23
|
+
` browser_start_timeout: 120,`,
|
|
24
|
+
` disable_watching: true,`,
|
|
25
|
+
` launch_in_ci: ['Chrome'],`,
|
|
26
|
+
` launch_in_dev: ['Chrome'],`,
|
|
27
|
+
` test_page: 'tests/index.html?hidepassed&nolint',`,
|
|
28
|
+
`};`,
|
|
29
|
+
``,
|
|
30
|
+
].join(EOL);
|
|
31
|
+
writeFileSync(join(projectRoot, filePath), file, 'utf8');
|
|
32
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { findFiles } from '@codemod-utils/files';
|
|
2
|
+
import { convertToEsm, createConfig } from './update-testem-config/index.js';
|
|
3
|
+
function findUserConfig(projectRoot) {
|
|
4
|
+
// https://github.com/testem/testem/blob/v3.21.5/lib/config.js#L73-L84
|
|
5
|
+
const filePaths = findFiles('{testem,.testem}.{cjs,js,json,mjs,yml}', {
|
|
6
|
+
projectRoot,
|
|
7
|
+
});
|
|
8
|
+
if (filePaths.length === 1) {
|
|
9
|
+
return filePaths[0];
|
|
10
|
+
}
|
|
11
|
+
return undefined;
|
|
12
|
+
}
|
|
13
|
+
export function updateTestemConfig(options) {
|
|
14
|
+
const { projectRoot } = options;
|
|
15
|
+
const filePath = findUserConfig(projectRoot);
|
|
16
|
+
if (filePath === undefined) {
|
|
17
|
+
createConfig(options);
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
if (filePath.endsWith('.cjs') || filePath.endsWith('.js')) {
|
|
21
|
+
convertToEsm(filePath, options);
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
const latestVersions = new Map([
|
|
2
|
+
['@ember/test-helpers', '^5.7.0'],
|
|
3
|
+
['@embroider/macros', '1.21.4'],
|
|
4
|
+
['@embroider/vite', '1.8.0'],
|
|
5
|
+
['@types/qunit', '2.19.14'],
|
|
6
|
+
['ember-qunit', '9.2.0'],
|
|
7
|
+
['ember-strict-application-resolver', '0.1.1'],
|
|
8
|
+
['ember-testem', '0.5.3'],
|
|
9
|
+
['qunit', '3.0.0'],
|
|
10
|
+
['qunit-dom', '3.6.0'],
|
|
11
|
+
['vite', '8.3.5'],
|
|
12
|
+
]);
|
|
13
|
+
export function getLatestVersion(packageName) {
|
|
14
|
+
if (!latestVersions.has(packageName)) {
|
|
15
|
+
throw new RangeError(`ERROR: The latest version of \`${packageName}\` is unknown.\n`);
|
|
16
|
+
}
|
|
17
|
+
return `^${latestVersions.get(packageName)}`;
|
|
18
|
+
}
|