ember-testem 0.1.0 → 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/README.md +238 -1
- package/dist/bin/ember-test.js +23 -3
- package/dist/src/steps/create-options.js +3 -2
- package/dist/src/steps/run-tests/run-tests-in-ci.js +4 -2
- package/dist/src/steps/run-tests/run-tests-in-dev.js +4 -2
- package/dist/src/utils/run-tests/get-query-params.js +10 -0
- package/package.json +9 -6
package/README.md
CHANGED
|
@@ -1,6 +1,243 @@
|
|
|
1
1
|
# ember-testem
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
_Backward- and forward-compatible testing for Ember projects_
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
## Quickstart
|
|
7
|
+
|
|
8
|
+
1\. Install `ember-testem` as a development dependency. The package provides an executable named `ember-test`.
|
|
9
|
+
|
|
10
|
+
```sh
|
|
11
|
+
pnpm add -D ember-testem
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
2\. Configure `testem` in `testem.mjs`.
|
|
15
|
+
|
|
16
|
+
```js
|
|
17
|
+
export default {
|
|
18
|
+
browser_args: {
|
|
19
|
+
Chrome: {
|
|
20
|
+
ci: [
|
|
21
|
+
// --no-sandbox is needed when running Chrome inside a container
|
|
22
|
+
process.env.CI ? '--no-sandbox' : null,
|
|
23
|
+
'--headless',
|
|
24
|
+
'--disable-dev-shm-usage',
|
|
25
|
+
'--disable-software-rasterizer',
|
|
26
|
+
'--mute-audio',
|
|
27
|
+
'--remote-debugging-port=0',
|
|
28
|
+
'--window-size=1440,900',
|
|
29
|
+
].filter(Boolean),
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
browser_start_timeout: 120,
|
|
33
|
+
disable_watching: true,
|
|
34
|
+
launch_in_ci: ['Chrome'],
|
|
35
|
+
launch_in_dev: ['Chrome'],
|
|
36
|
+
test_page: 'tests/index.html?hidepassed&nolint',
|
|
37
|
+
};
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
3\. Update the `test` script in `package.json` so that it separates concerns. Build the test app, then run it.
|
|
41
|
+
|
|
42
|
+
```diff
|
|
43
|
+
{
|
|
44
|
+
"scripts": {
|
|
45
|
+
"build": "..."
|
|
46
|
+
+ "build:test": "...",
|
|
47
|
+
- "test": "ember test"
|
|
48
|
+
+ "test": "pnpm build:test && ember-test"
|
|
49
|
+
+ "test:watch": "concurrently \"pnpm build:test --watch\" && \"pnpm ember-test --server\" --names build,test"
|
|
50
|
+
},
|
|
51
|
+
"devDependencies": {
|
|
52
|
+
"concurrently": "...",
|
|
53
|
+
+ "ember-testem": "..."
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Note, `test:watch` can encounter race conditions. Once the test build is complete, refresh the test browser to see the latest results.
|
|
59
|
+
|
|
60
|
+
<details>
|
|
61
|
+
|
|
62
|
+
<summary>V1 addons</summary>
|
|
63
|
+
|
|
64
|
+
See [my-v1-addon](../../tests/my-v1-addon) for an example.
|
|
65
|
+
|
|
66
|
+
```json
|
|
67
|
+
{
|
|
68
|
+
"scripts": {
|
|
69
|
+
"build": "ember build --environment production",
|
|
70
|
+
"build:test": "ember build --environment test"
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
</details>
|
|
76
|
+
|
|
77
|
+
<details>
|
|
78
|
+
|
|
79
|
+
<summary>V1 apps</summary>
|
|
80
|
+
|
|
81
|
+
See [my-v1-app](../../tests/my-v1-app) for an example.
|
|
82
|
+
|
|
83
|
+
```json
|
|
84
|
+
{
|
|
85
|
+
"scripts": {
|
|
86
|
+
"build": "ember build --environment production",
|
|
87
|
+
"build:test": "ember build --environment test"
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
</details>
|
|
93
|
+
|
|
94
|
+
<details>
|
|
95
|
+
|
|
96
|
+
<summary>V2 addons</summary>
|
|
97
|
+
|
|
98
|
+
See [my-v2-addon](../../tests/my-v2-addon) for an example.
|
|
99
|
+
|
|
100
|
+
For brevity, additional file changes aren't shown below. For example, you will need to split the Babel and TypeScript configurations into two files: one for production and another for testing.
|
|
101
|
+
|
|
102
|
+
```json
|
|
103
|
+
{
|
|
104
|
+
"scripts": {
|
|
105
|
+
"build": "rollup --config",
|
|
106
|
+
"build:test": "NODE_ENV=development vite build --config vite.test.config.mts --mode development"
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
```ts
|
|
112
|
+
/* vite.test.config.mts */
|
|
113
|
+
import { extensions, ember } from '@embroider/vite';
|
|
114
|
+
import { babel } from '@rollup/plugin-babel';
|
|
115
|
+
import { defineConfig } from 'vite';
|
|
116
|
+
|
|
117
|
+
export default defineConfig({
|
|
118
|
+
build: {
|
|
119
|
+
minify: false,
|
|
120
|
+
rollupOptions: {
|
|
121
|
+
input: {
|
|
122
|
+
tests: 'tests/index.html',
|
|
123
|
+
},
|
|
124
|
+
},
|
|
125
|
+
sourcemap: true,
|
|
126
|
+
},
|
|
127
|
+
plugins: [
|
|
128
|
+
ember(),
|
|
129
|
+
babel({
|
|
130
|
+
babelHelpers: 'inline',
|
|
131
|
+
extensions,
|
|
132
|
+
parallel: true,
|
|
133
|
+
}),
|
|
134
|
+
],
|
|
135
|
+
});
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
</details>
|
|
139
|
+
|
|
140
|
+
<details>
|
|
141
|
+
|
|
142
|
+
<summary>V2 apps</summary>
|
|
143
|
+
|
|
144
|
+
See [my-v2-app](../../tests/my-v2-app) for an example.
|
|
145
|
+
|
|
146
|
+
```json
|
|
147
|
+
{
|
|
148
|
+
"scripts": {
|
|
149
|
+
"build": "vite build",
|
|
150
|
+
"build:test": "NODE_ENV=development vite build --config vite.test.config.mts --mode development"
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
```ts
|
|
156
|
+
/* vite.test.config.mts */
|
|
157
|
+
import { defineConfig } from 'vite';
|
|
158
|
+
|
|
159
|
+
import baseConfiguration from './vite.config.mts';
|
|
160
|
+
|
|
161
|
+
export default defineConfig({
|
|
162
|
+
...baseConfiguration,
|
|
163
|
+
build: {
|
|
164
|
+
minify: false,
|
|
165
|
+
sourcemap: true,
|
|
166
|
+
},
|
|
167
|
+
});
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
</details>
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
### Arguments
|
|
174
|
+
|
|
175
|
+
<details>
|
|
176
|
+
|
|
177
|
+
<summary>Optional: Launch test browser</summary>
|
|
178
|
+
|
|
179
|
+
Pass `--server` (`-s`) to launch a browser. This may be useful for debugging (e.g. with `debugger` or `await this.pauseTest()`) and re-running the tests after a code change (don't forget to pass `--watch` to `build:test`).
|
|
180
|
+
|
|
181
|
+
```sh
|
|
182
|
+
ember-test --server
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
</details>
|
|
186
|
+
|
|
187
|
+
<details>
|
|
188
|
+
|
|
189
|
+
<summary>Optional: Specify filters for QUnit</summary>
|
|
190
|
+
|
|
191
|
+
The `--module` (`-m`) option allows you to select a module—a group of tests inside a `module()`.
|
|
192
|
+
|
|
193
|
+
```sh
|
|
194
|
+
ember-test --module "Integration | Component | ui/form/input"
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
The `--filter` (`-f`) is more versatile. You can provide a keyword to match against the modules and test descriptions. A test description is what appears in `test()`.
|
|
198
|
+
|
|
199
|
+
```sh
|
|
200
|
+
ember-test --filter integration
|
|
201
|
+
ember-test --filter ui/form
|
|
202
|
+
# Exclude acceptance tests
|
|
203
|
+
ember-test --filter \!acceptance
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
</details>
|
|
207
|
+
|
|
208
|
+
<details>
|
|
209
|
+
|
|
210
|
+
<summary>Optional: Specify path to test build</summary>
|
|
211
|
+
|
|
212
|
+
By default, `ember-testem` assumes `dist` to be the path to the test build.
|
|
213
|
+
|
|
214
|
+
Pass `--path` to indicate otherwise. This may be useful if you want to create the production and test builds in different locations.
|
|
215
|
+
|
|
216
|
+
```sh
|
|
217
|
+
ember-test --path dist-for-testing
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
</details>
|
|
221
|
+
|
|
222
|
+
<details>
|
|
223
|
+
|
|
224
|
+
<summary>Optional: Specify test port</summary>
|
|
225
|
+
|
|
226
|
+
By default, `ember-testem` runs tests on port `7357`.
|
|
227
|
+
|
|
228
|
+
Pass `--port` (or `--test-port`, currently supported for backward compatibility) to pick a different port. You can pass `0` to pick any available port (useful for testing multiple projects in parallel).
|
|
229
|
+
|
|
230
|
+
```sh
|
|
231
|
+
ember-test --port 0
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
</details>
|
|
235
|
+
|
|
236
|
+
> [!NOTE]
|
|
237
|
+
>
|
|
238
|
+
> `ember-testem` provides a limited API on purpose.
|
|
239
|
+
>
|
|
240
|
+
> For `ember-cli` options like `--host`, `--launch`, `--reporter`, `--ssl`, `--ssl-cert`, `--ssl-key`, `--test-page`, `--testem-debug`), [configure `testem` in `testem.mjs` instead](https://github.com/ember-cli/ember-cli/blob/v7.3.0-ember-cli/lib/tasks/test.js#L54-L71).
|
|
4
241
|
|
|
5
242
|
|
|
6
243
|
## Compatibility
|
package/dist/bin/ember-test.js
CHANGED
|
@@ -7,12 +7,27 @@ import { run } from '../src/run.js';
|
|
|
7
7
|
process.title = 'ember-test';
|
|
8
8
|
// Set codemod options
|
|
9
9
|
const argv = yargs(hideBin(process.argv))
|
|
10
|
+
.option('filter', {
|
|
11
|
+
alias: 'f',
|
|
12
|
+
describe: 'Specify a keyword for which modules and tests to run',
|
|
13
|
+
type: 'string',
|
|
14
|
+
})
|
|
15
|
+
.option('module', {
|
|
16
|
+
alias: 'm',
|
|
17
|
+
describe: 'Specify the name of a module to run',
|
|
18
|
+
type: 'string',
|
|
19
|
+
})
|
|
10
20
|
.option('path', {
|
|
21
|
+
default: 'dist',
|
|
11
22
|
describe: 'Relative path to the test build',
|
|
12
23
|
type: 'string',
|
|
24
|
+
})
|
|
25
|
+
.option('port', {
|
|
26
|
+
describe: 'Port for running tests. Pass 0 to automatically pick an available port.',
|
|
27
|
+
type: 'number',
|
|
13
28
|
})
|
|
14
29
|
.option('root', {
|
|
15
|
-
describe: '
|
|
30
|
+
describe: 'Project root',
|
|
16
31
|
type: 'string',
|
|
17
32
|
})
|
|
18
33
|
.option('server', {
|
|
@@ -24,11 +39,16 @@ const argv = yargs(hideBin(process.argv))
|
|
|
24
39
|
describe: 'Port for running tests. Pass 0 to automatically pick an available port.',
|
|
25
40
|
type: 'number',
|
|
26
41
|
})
|
|
42
|
+
.deprecateOption('test-port', 'Use --port instead.')
|
|
27
43
|
.parseSync();
|
|
28
44
|
const codemodOptions = {
|
|
29
|
-
buildPath: argv['path']
|
|
45
|
+
buildPath: argv['path'],
|
|
46
|
+
filters: {
|
|
47
|
+
filter: argv['filter'],
|
|
48
|
+
module: argv['module'],
|
|
49
|
+
},
|
|
50
|
+
port: argv['test-port'] ?? argv['port'],
|
|
30
51
|
projectRoot: argv['root'] ?? process.cwd(),
|
|
31
52
|
server: argv['server'],
|
|
32
|
-
testPort: argv['test-port'],
|
|
33
53
|
};
|
|
34
54
|
void run(codemodOptions);
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
export function createOptions(codemodOptions) {
|
|
2
|
-
const { buildPath, projectRoot, server
|
|
2
|
+
const { buildPath, filters, port, projectRoot, server } = codemodOptions;
|
|
3
3
|
return {
|
|
4
4
|
buildPath,
|
|
5
|
+
filters,
|
|
5
6
|
launchBrowser: Boolean(server),
|
|
7
|
+
port,
|
|
6
8
|
projectRoot,
|
|
7
|
-
testPort,
|
|
8
9
|
};
|
|
9
10
|
}
|
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
import { join } from 'node:path';
|
|
2
2
|
import Testem from 'testem';
|
|
3
|
+
import { getQueryParams } from '../../utils/run-tests/get-query-params.js';
|
|
3
4
|
export async function runTestsInCI(options) {
|
|
4
|
-
const { buildPath,
|
|
5
|
+
const { buildPath, filters, port, projectRoot } = options;
|
|
5
6
|
const testemInstance = new Testem();
|
|
6
7
|
const startOptions = {
|
|
7
8
|
launch: false,
|
|
8
|
-
port
|
|
9
|
+
port,
|
|
9
10
|
};
|
|
10
11
|
testemInstance.setDefaultOptions({
|
|
11
12
|
...startOptions,
|
|
12
13
|
config_dir: projectRoot,
|
|
13
14
|
cwd: join(projectRoot, buildPath),
|
|
14
15
|
parallel: 1,
|
|
16
|
+
query_params: getQueryParams(filters),
|
|
15
17
|
});
|
|
16
18
|
return new Promise((resolve, reject) => {
|
|
17
19
|
testemInstance.startCI(startOptions, (exitCode, error) => {
|
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
import { join } from 'node:path';
|
|
2
2
|
import { watch } from 'chokidar';
|
|
3
3
|
import Testem from 'testem';
|
|
4
|
+
import { getQueryParams } from '../../utils/run-tests/get-query-params.js';
|
|
4
5
|
export async function runTestsInDev(options) {
|
|
5
|
-
const { buildPath,
|
|
6
|
+
const { buildPath, filters, port, projectRoot } = options;
|
|
6
7
|
const testemInstance = new Testem();
|
|
7
8
|
const startOptions = {
|
|
8
9
|
launch: false,
|
|
9
|
-
port
|
|
10
|
+
port,
|
|
10
11
|
};
|
|
11
12
|
testemInstance.setDefaultOptions({
|
|
12
13
|
...startOptions,
|
|
13
14
|
config_dir: projectRoot,
|
|
14
15
|
cwd: join(projectRoot, buildPath),
|
|
16
|
+
query_params: getQueryParams(filters),
|
|
15
17
|
});
|
|
16
18
|
const watcher = watch([buildPath], {
|
|
17
19
|
awaitWriteFinish: true,
|
package/package.json
CHANGED
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ember-testem",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "",
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"description": "Backward- and forward-compatible testing for Ember projects",
|
|
5
5
|
"keywords": [
|
|
6
|
-
"
|
|
7
|
-
"ember
|
|
8
|
-
"emberjs"
|
|
6
|
+
"ci",
|
|
7
|
+
"ember",
|
|
8
|
+
"emberjs",
|
|
9
|
+
"testem",
|
|
10
|
+
"testing"
|
|
9
11
|
],
|
|
10
12
|
"repository": {
|
|
11
13
|
"type": "git",
|
|
12
|
-
"url": "https://github.com/ijlee2/ember-test.git"
|
|
14
|
+
"url": "https://github.com/ijlee2/ember-test.git",
|
|
15
|
+
"directory": "packages/ember-testem"
|
|
13
16
|
},
|
|
14
17
|
"license": "MIT",
|
|
15
18
|
"author": "Isaac J. Lee",
|