ember-testem 0.4.0 → 0.5.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,17 @@
3
3
  _Backward- and forward-compatible testing for Ember projects_
4
4
 
5
5
 
6
+ ## Why?
7
+
8
+ Until now, testing Ember apps and addons required `ember-cli`, a monolith package that is written in JavaScript and has little relevance in v2 apps and v2 addons. Ember's test ecosystem (e.g. `ember-exam`, `@percy/ember`) is at risk because it is built on `ember-cli`.
9
+
10
+ `ember-testem` aims to show that:
11
+
12
+ - The fix is minimal, backward-, and forward-compatible (apps with strict resolver, apps without `ember-cli`).
13
+ - We can keep using `qunit` and `testem`. No need to switch to another test framework and rewrite tests.
14
+ - We can keep using battle-tested packages like `@percy/ember`, `ember-a11y-testing`, `ember-qunit`, `ember-test-selectors`, `miragejs`, and `qunit-dom`.
15
+
16
+
6
17
  ## Quickstart
7
18
 
8
19
  1\. Install `ember-testem` as a development dependency. The package provides an executable named `ember-test`.
@@ -37,7 +48,7 @@ export default {
37
48
  };
38
49
  ```
39
50
 
40
- 3\. Update the `test` script in `package.json` so that it separates concerns. Build the test app, then run it.
51
+ 3\. Update the `test` script in `package.json` so that it builds the test app, then runs the app (the tests).
41
52
 
42
53
  ```diff
43
54
  {
@@ -55,7 +66,7 @@ export default {
55
66
  }
56
67
  ```
57
68
 
58
- Note, `test:watch` can encounter race conditions. Once the test build is complete, refresh the test browser to see the latest results.
69
+ Note, `test:watch` may encounter race conditions. Once the build is complete, refresh the test browser to see the latest results.
59
70
 
60
71
  <details>
61
72
 
@@ -214,6 +225,24 @@ ember-test --port 0
214
225
 
215
226
  </details>
216
227
 
228
+ <details>
229
+
230
+ <summary>Optional: Randomize tests</summary>
231
+
232
+ Pass `--random` to randomize the order of tests. This helps you guarantee that your tests are independent of one another.
233
+
234
+ ```sh
235
+ ember-test --random
236
+ ```
237
+
238
+ You can also pass a seed to run tests in a particular random order.
239
+
240
+ ```sh
241
+ ember-test --random gflqlwrm59j
242
+ ```
243
+
244
+ </details>
245
+
217
246
  > [!NOTE]
218
247
  >
219
248
  > `ember-testem` provides a limited API on purpose.
@@ -25,6 +25,10 @@ const argv = yargs(hideBin(process.argv))
25
25
  .option('port', {
26
26
  describe: 'Port for running tests. Pass 0 to automatically pick an available port.',
27
27
  type: 'number',
28
+ })
29
+ .option('random', {
30
+ describe: 'Randomize the order of tests (with a seed)',
31
+ type: 'string',
28
32
  })
29
33
  .option('root', {
30
34
  describe: 'Project root',
@@ -47,7 +51,8 @@ const codemodOptions = {
47
51
  projectRoot: argv['root'] ?? process.cwd(),
48
52
  qunit: {
49
53
  filter: argv['filter'],
50
- testModule: argv['module'],
54
+ module: argv['module'],
55
+ random: argv['random'],
51
56
  },
52
57
  server: argv['server'],
53
58
  };
@@ -1,3 +1,4 @@
1
+ import { createSeed } from '../utils/create-options/create-seed.js';
1
2
  export function createOptions(codemodOptions) {
2
3
  const { buildPath, port, projectRoot, qunit, server } = codemodOptions;
3
4
  return {
@@ -5,6 +6,10 @@ export function createOptions(codemodOptions) {
5
6
  launchBrowser: Boolean(server),
6
7
  port,
7
8
  projectRoot,
8
- qunit,
9
+ qunit: {
10
+ filter: qunit.filter,
11
+ module: qunit.module,
12
+ seed: createSeed(qunit.random),
13
+ },
9
14
  };
10
15
  }
@@ -0,0 +1,15 @@
1
+ export function createSeed(seed) {
2
+ switch (seed) {
3
+ case undefined: {
4
+ return undefined;
5
+ }
6
+ case '': {
7
+ const seedNew = Math.random().toString(36).slice(2);
8
+ console.log(`Randomizing tests with seed: ${seedNew}`);
9
+ return seedNew;
10
+ }
11
+ default: {
12
+ return seed;
13
+ }
14
+ }
15
+ }
@@ -1,11 +1,14 @@
1
1
  export function getQueryParams(options) {
2
2
  const { qunit } = options;
3
3
  const params = [];
4
- if (qunit.testModule) {
5
- params.push(`module=${qunit.testModule}`);
4
+ if (qunit.module) {
5
+ params.push(`module=${qunit.module}`);
6
6
  }
7
7
  if (qunit.filter) {
8
8
  params.push(`filter=${qunit.filter}`);
9
9
  }
10
+ if (qunit.seed) {
11
+ params.push(`seed=${qunit.seed}`);
12
+ }
10
13
  return params.join('&');
11
14
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ember-testem",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "description": "Backward- and forward-compatible testing for Ember projects",
5
5
  "keywords": [
6
6
  "ci",
@@ -11,7 +11,7 @@
11
11
  ],
12
12
  "repository": {
13
13
  "type": "git",
14
- "url": "https://github.com/ijlee2/ember-test.git",
14
+ "url": "https://github.com/ijlee2/ember-testem.git",
15
15
  "directory": "packages/ember-testem"
16
16
  },
17
17
  "license": "MIT",