ember-testem 0.1.0 → 0.2.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 CHANGED
@@ -3,6 +3,238 @@
3
3
  _Forward- and backward-compatible testing for Ember projects_
4
4
 
5
5
 
6
+ ## Quickstart
7
+
8
+ 1\. Install `ember-testem` as a development dependency.
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
+ },
50
+ "devDependencies": {
51
+ + "ember-testem": "..."
52
+ }
53
+ }
54
+ ```
55
+
56
+ <details>
57
+
58
+ <summary>V1 addons</summary>
59
+
60
+ See [my-v1-addon](../../tests/my-v1-addon) for an example.
61
+
62
+ ```json
63
+ {
64
+ "scripts": {
65
+ "build": "ember build --environment production",
66
+ "build:test": "ember build --environment test"
67
+ }
68
+ }
69
+ ```
70
+
71
+ </details>
72
+
73
+ <details>
74
+
75
+ <summary>V1 apps</summary>
76
+
77
+ See [my-v1-app](../../tests/my-v1-app) for an example.
78
+
79
+ ```json
80
+ {
81
+ "scripts": {
82
+ "build": "ember build --environment production",
83
+ "build:test": "ember build --environment test"
84
+ }
85
+ }
86
+ ```
87
+
88
+ </details>
89
+
90
+ <details>
91
+
92
+ <summary>V2 addons</summary>
93
+
94
+ See [my-v2-addon](../../tests/my-v2-addon) for an example.
95
+
96
+ 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.
97
+
98
+ ```json
99
+ {
100
+ "scripts": {
101
+ "build": "rollup --config",
102
+ "build:test": "NODE_ENV=development vite build --config \"vite.test.config.mts\" --mode development"
103
+ }
104
+ }
105
+ ```
106
+
107
+ ```ts
108
+ /* vite.test.config.mts */
109
+ import { extensions, ember } from '@embroider/vite';
110
+ import { babel } from '@rollup/plugin-babel';
111
+ import { defineConfig } from 'vite';
112
+
113
+ export default defineConfig({
114
+ build: {
115
+ minify: false,
116
+ rollupOptions: {
117
+ input: {
118
+ tests: 'tests/index.html',
119
+ },
120
+ },
121
+ sourcemap: true,
122
+ },
123
+ plugins: [
124
+ ember(),
125
+ babel({
126
+ babelHelpers: 'inline',
127
+ extensions,
128
+ }),
129
+ ],
130
+ });
131
+ ```
132
+
133
+ </details>
134
+
135
+ <details>
136
+
137
+ <summary>V2 apps</summary>
138
+
139
+ See [my-v2-app](../../tests/my-v2-app) for an example.
140
+
141
+ ```json
142
+ {
143
+ "scripts": {
144
+ "build": "vite build",
145
+ "build:test": "NODE_ENV=development vite build --config \"vite.test.config.mts\" --mode development"
146
+ }
147
+ }
148
+ ```
149
+
150
+ ```ts
151
+ /* vite.test.config.mts */
152
+ import type { UserConfig } from 'vite';
153
+
154
+ import baseConfiguration from './vite.config.mts';
155
+
156
+ export default {
157
+ ...baseConfiguration,
158
+ build: {
159
+ minify: false,
160
+ sourcemap: true,
161
+ },
162
+ } satisfies UserConfig;
163
+ ```
164
+
165
+ </details>
166
+
167
+
168
+ ### Arguments
169
+
170
+ <details>
171
+
172
+ <summary>Optional: Launch test browser</summary>
173
+
174
+ 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`).
175
+
176
+ ```sh
177
+ ember-test --server
178
+ ```
179
+
180
+ </details>
181
+
182
+ <details>
183
+
184
+ <summary>Optional: Specify filters for QUnit</summary>
185
+
186
+ The `--module` (`-m`) option allows you to select a module—a group of tests inside a `module()`.
187
+
188
+ ```sh
189
+ ember-test --module "Integration | Component | ui/form/input"
190
+ ```
191
+
192
+ 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()`.
193
+
194
+ ```sh
195
+ ember-test --filter integration
196
+ ember-test --filter ui/form
197
+ # Exclude acceptance tests
198
+ ember-test --filter \!acceptance
199
+ ```
200
+
201
+ </details>
202
+
203
+ <details>
204
+
205
+ <summary>Optional: Specify path to test build</summary>
206
+
207
+ By default, `ember-testem` assumes `dist` to be the path to the test build.
208
+
209
+ Pass `--path` to indicate otherwise. This may be useful if you want to create the production and test builds in different locations.
210
+
211
+ ```sh
212
+ ember-test --path "dist-for-testing"
213
+ ```
214
+
215
+ </details>
216
+
217
+ <details>
218
+
219
+ <summary>Optional: Specify test port</summary>
220
+
221
+ By default, `ember-testem` runs tests on port `7357`.
222
+
223
+ Pass `--test-port` to pick a different port. You can pass `0` to pick any available port (useful for testing multiple projects in parallel).
224
+
225
+ ```sh
226
+ ember-test --test-port 0
227
+ ```
228
+
229
+ </details>
230
+
231
+ > [!NOTE]
232
+ >
233
+ > `ember-testem` provides a limited API on purpose.
234
+ >
235
+ > 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).
236
+
237
+
6
238
  ## Compatibility
7
239
 
8
240
  - Node.js v22 or above
@@ -7,6 +7,16 @@ 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', {
11
21
  describe: 'Relative path to the test build',
12
22
  type: 'string',
@@ -27,6 +37,10 @@ const argv = yargs(hideBin(process.argv))
27
37
  .parseSync();
28
38
  const codemodOptions = {
29
39
  buildPath: argv['path'] ?? 'dist',
40
+ filters: {
41
+ filter: argv['filter'],
42
+ module: argv['module'],
43
+ },
30
44
  projectRoot: argv['root'] ?? process.cwd(),
31
45
  server: argv['server'],
32
46
  testPort: argv['test-port'],
@@ -1,7 +1,8 @@
1
1
  export function createOptions(codemodOptions) {
2
- const { buildPath, projectRoot, server, testPort } = codemodOptions;
2
+ const { buildPath, filters, projectRoot, server, testPort } = codemodOptions;
3
3
  return {
4
4
  buildPath,
5
+ filters,
5
6
  launchBrowser: Boolean(server),
6
7
  projectRoot,
7
8
  testPort,
@@ -1,7 +1,8 @@
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, projectRoot, testPort } = options;
5
+ const { buildPath, filters, projectRoot, testPort } = options;
5
6
  const testemInstance = new Testem();
6
7
  const startOptions = {
7
8
  launch: false,
@@ -12,6 +13,7 @@ export async function runTestsInCI(options) {
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,8 +1,9 @@
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, projectRoot, testPort } = options;
6
+ const { buildPath, filters, projectRoot, testPort } = options;
6
7
  const testemInstance = new Testem();
7
8
  const startOptions = {
8
9
  launch: false,
@@ -12,6 +13,7 @@ export async function runTestsInDev(options) {
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,
@@ -0,0 +1,10 @@
1
+ export function getQueryParams(filters) {
2
+ const params = [];
3
+ if (filters.module) {
4
+ params.push(`module=${filters.module}`);
5
+ }
6
+ if (filters.filter) {
7
+ params.push(`filter=${filters.filter}`);
8
+ }
9
+ return params.join('&');
10
+ }
package/package.json CHANGED
@@ -1,15 +1,18 @@
1
1
  {
2
2
  "name": "ember-testem",
3
- "version": "0.1.0",
4
- "description": "",
3
+ "version": "0.2.0",
4
+ "description": "Forward- and backward-compatible testing for Ember projects",
5
5
  "keywords": [
6
- "codemod",
7
- "ember-codemod",
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",