qunitx-cli 0.0.2 → 0.1.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.
Files changed (80) hide show
  1. package/.github/dependabot.yml +7 -0
  2. package/.github/workflows/push.yml +36 -0
  3. package/CHANGELOG.md +16 -0
  4. package/Dockerfile +24 -0
  5. package/LICENSE +22 -0
  6. package/TODO +90 -0
  7. package/build.js +54 -1
  8. package/cli.js +24 -1
  9. package/lib/boilerplates/default-project-config-values.js +6 -0
  10. package/lib/boilerplates/setup/tests.hbs +15 -0
  11. package/lib/boilerplates/setup/tsconfig.json +109 -0
  12. package/lib/boilerplates/test.js +25 -0
  13. package/lib/commands/generate.js +33 -0
  14. package/lib/commands/help.js +37 -0
  15. package/lib/commands/init.js +70 -0
  16. package/lib/commands/run/tests-in-browser.js +162 -0
  17. package/lib/commands/run.js +119 -0
  18. package/lib/servers/http.js +233 -0
  19. package/lib/setup/bind-server-to-port.js +14 -0
  20. package/lib/setup/browser.js +55 -0
  21. package/lib/setup/config.js +46 -0
  22. package/lib/setup/file-watcher.js +72 -0
  23. package/lib/setup/fs-tree.js +48 -0
  24. package/lib/setup/keyboard-events.js +34 -0
  25. package/lib/setup/test-file-paths.js +79 -0
  26. package/lib/setup/web-server.js +241 -0
  27. package/lib/setup/write-output-static-files.js +22 -0
  28. package/lib/tap/display-final-result.js +15 -0
  29. package/lib/tap/display-test-result.js +73 -0
  30. package/lib/utils/find-internal-assets-from-html.js +16 -0
  31. package/lib/utils/find-project-root.js +17 -0
  32. package/lib/utils/indent-string.js +11 -0
  33. package/lib/utils/listen-to-keyboard-key.js +44 -0
  34. package/lib/utils/parse-cli-flags.js +57 -0
  35. package/lib/utils/path-exists.js +11 -0
  36. package/lib/utils/resolve-port-number-for.js +27 -0
  37. package/lib/utils/run-user-module.js +18 -0
  38. package/lib/utils/search-in-parent-directories.js +15 -0
  39. package/lib/utils/time-counter.js +8 -0
  40. package/package.json +8 -5
  41. package/test/commands/help-test.js +72 -0
  42. package/test/commands/index.js +2 -0
  43. package/test/commands/init-test.js +44 -0
  44. package/test/flags/after-test.js +23 -0
  45. package/test/flags/before-test.js +23 -0
  46. package/test/flags/coverage-test.js +6 -0
  47. package/test/flags/failfast-test.js +5 -0
  48. package/test/flags/index.js +2 -0
  49. package/test/flags/output-test.js +6 -0
  50. package/test/flags/reporter-test.js +6 -0
  51. package/test/flags/timeout-test.js +6 -0
  52. package/test/flags/watch-test.js +6 -0
  53. package/test/helpers/after-script-async.js +13 -0
  54. package/test/helpers/after-script-basic.js +1 -0
  55. package/test/helpers/assert-stdout.js +112 -0
  56. package/test/helpers/before-script-async.js +35 -0
  57. package/test/helpers/before-script-basic.js +1 -0
  58. package/test/helpers/before-script-web-server-tests.js +28 -0
  59. package/test/helpers/failing-tests.js +49 -0
  60. package/test/helpers/failing-tests.ts +49 -0
  61. package/test/helpers/fs-writers.js +36 -0
  62. package/test/helpers/index-with-content.html +20 -0
  63. package/test/helpers/index-without-content.html +22 -0
  64. package/test/helpers/passing-tests-dist.js +4883 -0
  65. package/test/helpers/passing-tests.js +44 -0
  66. package/test/helpers/passing-tests.ts +44 -0
  67. package/test/helpers/shell.js +37 -0
  68. package/test/index.js +22 -0
  69. package/test/inputs/advanced-htmls-test.js +21 -0
  70. package/test/inputs/error-edge-cases-test.js +11 -0
  71. package/test/inputs/file-and-folder-test.js +11 -0
  72. package/test/inputs/file-test.js +169 -0
  73. package/test/inputs/folder-test.js +193 -0
  74. package/test/inputs/index.js +5 -0
  75. package/test/setup/index.js +1 -0
  76. package/test/setup/test-file-paths-test.js +33 -0
  77. package/test/setup.js +17 -0
  78. package/vendor/package.json +1 -0
  79. package/vendor/qunit.css +525 -0
  80. package/vendor/qunit.js +7037 -0
@@ -0,0 +1,27 @@
1
+ export default async function resolvePortNumberFor(portNumber) {
2
+ if (await portIsAvailable(portNumber)) {
3
+ return portNumber;
4
+ }
5
+
6
+ return (await resolvePortNumberFor(portNumber + 1));
7
+ }
8
+
9
+ function portIsAvailable(portNumber) {
10
+ return new Promise(async (resolve) => {
11
+ const net = await import('net');
12
+ const server = net.createServer();
13
+
14
+ server.once('error', function(err) {
15
+ if (err.code === 'EADDRINUSE') {
16
+ resolve(false);
17
+ }
18
+ });
19
+
20
+ server.once('listening', function() {
21
+ server.close();
22
+ resolve(true);
23
+ });
24
+
25
+ server.listen(portNumber);
26
+ });
27
+ }
@@ -0,0 +1,18 @@
1
+ import kleur from 'kleur';
2
+
3
+ export default async function runUserModule(modulePath, params, scriptPosition) {
4
+ try {
5
+ let func = await import(modulePath);
6
+ if (func) {
7
+ func.default ?
8
+ await func.default(params) :
9
+ typeof func === 'function' ? await func(params) : null;
10
+ }
11
+ } catch (error) {
12
+ console.log('#', kleur.red(`QUnitX ${scriptPosition} script failed:`));
13
+ console.trace(error);
14
+ console.error(error);
15
+
16
+ return process.exit(1);
17
+ }
18
+ }
@@ -0,0 +1,15 @@
1
+ import pathExists from './path-exists.js';
2
+
3
+ async function searchInParentDirectories(directory, targetEntry) {
4
+ directory = directory === '.' ? process.cwd() : directory;
5
+
6
+ if (await pathExists(`${directory}/${targetEntry}`)) {
7
+ return `${directory}/${targetEntry}`;
8
+ } else if (directory === '') {
9
+ return;
10
+ }
11
+
12
+ return await searchInParentDirectories(directory.slice(0, directory.lastIndexOf('/')), targetEntry);
13
+ }
14
+
15
+ export default searchInParentDirectories;
@@ -0,0 +1,8 @@
1
+ export default function() {
2
+ const startTime = new Date();
3
+
4
+ return {
5
+ startTime: startTime,
6
+ stop: () => +(new Date()) - (+startTime)
7
+ };
8
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "qunitx-cli",
3
3
  "type": "module",
4
- "version": "0.0.2",
4
+ "version": "0.1.0",
5
5
  "description": "Browser runner for QUnitx: run your qunitx tests in google-chrome",
6
6
  "main": "index.js",
7
7
  "author": "Izel Nakri",
@@ -23,7 +23,10 @@
23
23
  "prepack": "npm run build",
24
24
  "release:alpha": "node_modules/.bin/release-it --preRelease=alpha --no-git.requireUpstream",
25
25
  "release:beta": "node_modules/.bin/release-it --preRelease=beta --no-git.requireUpstream",
26
- "release": "node_modules/.bin/release-it"
26
+ "release": "node_modules/.bin/release-it",
27
+ "test": "node --test test/index.js",
28
+ "test:sanity-first": "./cli.js test/helpers/failing-tests.js test/helpers/failing-tests.ts",
29
+ "test:sanity-second": "./cli.js test/helpers/passing-tests.js test/helpers/passing-tests.ts"
27
30
  },
28
31
  "engines": {
29
32
  "node": ">=20.3.0"
@@ -38,12 +41,12 @@
38
41
  "dependencies": {
39
42
  "cheerio": "^1.0.0-rc.10",
40
43
  "chokidar": "^3.5.3",
41
- "esbuild": "^0.18.12",
44
+ "esbuild": "^0.18.14",
42
45
  "js-yaml": "^4.1.0",
43
46
  "jsdom": "^22.0.0",
44
47
  "kleur": "^4.1.5",
45
48
  "picomatch": "^2.3.1",
46
- "puppeteer": "20.8.2",
49
+ "puppeteer": "20.8.3",
47
50
  "recursive-lookup": "1.1.0",
48
51
  "ws": "^8.13.0"
49
52
  },
@@ -54,7 +57,7 @@
54
57
  "prettier": "^3.0.0",
55
58
  "qunit": "^2.19.4",
56
59
  "qunitx": "^0.6.0",
57
- "release-it": "^16.1.0"
60
+ "release-it": "^16.1.2"
58
61
  },
59
62
  "volta": {
60
63
  "node": "20.4.0"
@@ -0,0 +1,72 @@
1
+ import { module, test } from 'qunitx';
2
+ import process from "node:process";
3
+ import fs from 'node:fs';
4
+ import { promisify } from 'node:util';
5
+ import { exec } from 'node:child_process';
6
+
7
+ const CWD = process.cwd();
8
+ const VERSION = JSON.parse(fs.readFileSync(`${CWD}/package.json`)).version;
9
+ const shell = promisify(exec);
10
+ const cli = async function(arg = '') {
11
+ if (process.argv[0].includes('deno')) {
12
+ return await shell(`deno run --allow-read --allow-env ${CWD}/deno/cli.js ${arg}`);
13
+ }
14
+
15
+ return await shell(`node ${CWD}/cli.js ${arg}`);
16
+ }
17
+
18
+ const printedHelpOutput = `[qunitx v${VERSION}] Usage: qunitx [targets] --$flags
19
+
20
+ Input options:
21
+ - File: $ qunitx test/foo.js
22
+ - Folder: $ qunitx test/login
23
+ - Globs: $ qunitx test/**/*-test.js
24
+ - Combination: $ qunitx test/foo.js test/bar.js test/*-test.js test/logout
25
+
26
+ Optional flags:
27
+ --debug : print console output when tests run in browser
28
+ --watch : run the target file or folders, watch them for continuous run and expose http server under localhost
29
+ --timeout : change default timeout per test case
30
+ --output : folder to distribute built qunitx html and js that a webservers can run[default: tmp]
31
+ --failFast : run the target file or folders with immediate abort if a single test fails
32
+ --before : run a script before the tests(i.e start a new web server before tests)
33
+ --after : run a script after the tests(i.e save test results to a file)
34
+
35
+ Example: $ qunitx test/foo.ts app/e2e --debug --watch --before=scripts/start-new-webserver.js --after=scripts/write-test-results.js
36
+
37
+ Commands:
38
+ $ qunitx init # Bootstraps qunitx base html and add qunitx config to package.json if needed
39
+ $ qunitx new $testFileName # Creates a qunitx test file`;
40
+
41
+ module('Commands | Help tests', () => {
42
+ test('$ qunitx -> prints help text', async (assert) => {
43
+ const { stdout } = await cli();
44
+
45
+ console.log(stdout);
46
+ assert.ok(stdout.includes(printedHelpOutput));
47
+ });
48
+
49
+ test('$ qunitx print -> prints help text', async (assert) => {
50
+ const { stdout } = await cli('print');
51
+
52
+ assert.ok(stdout.includes(printedHelpOutput));
53
+ });
54
+
55
+ test('$ qunitx p -> prints help text', async (assert) => {
56
+ const { stdout } = await cli('p');
57
+
58
+ assert.ok(stdout.includes(printedHelpOutput));
59
+ });
60
+
61
+ test('$ qunitx help -> prints help text', async (assert) => {
62
+ const { stdout } = await cli('help');
63
+
64
+ assert.ok(stdout.includes(printedHelpOutput));
65
+ });
66
+
67
+ test('$ qunitx h -> prints help text', async (assert) => {
68
+ const { stdout } = await cli('h');
69
+
70
+ assert.ok(stdout.includes(printedHelpOutput));
71
+ });
72
+ });
@@ -0,0 +1,2 @@
1
+ import "./help-test.js";
2
+ // import "./init-test.js";
@@ -0,0 +1,44 @@
1
+ import { module, test } from 'qunitx';
2
+ import assert from 'node:assert';
3
+ import { promisify } from 'node:util';
4
+ import { exec } from 'node:child_process';
5
+
6
+ const shell = promisify(exec);
7
+ const cli = async function(arg = '') {
8
+ if (process.argv[0].includes('deno')) {
9
+ return await shell(`deno run --allow-read ${CWD}/deno/cli.js ${arg}`);
10
+ }
11
+
12
+ return await shell(`deno run --allow-read ${CWD}/cli.js ${arg}`);
13
+ }
14
+
15
+ module('Commands | init tests', () => {
16
+ test('$ qunitx init -> creates the test.html and correctly', async () => {
17
+ // assert missing
18
+ const { stdout } = await cli('init');
19
+ // assert added
20
+ });
21
+
22
+ // it('$ qunitx init warns existing files and assigns attributes to package.json', async function() {
23
+
24
+ // });
25
+
26
+ // it('$ qunitx init -> recreates missing files from package.json if it exists', async function() {
27
+
28
+ // });
29
+ });
30
+
31
+ async function stripQUnitXFromPackageJSON() {
32
+
33
+ }
34
+
35
+ // it('$ qunitx unknown -> raises error', async function() {
36
+ // t.plan(2);
37
+
38
+ // try {
39
+ // await shell(`node ${process.cwd()}/cli.js dasd`);
40
+ // } catch ({ stdout }) {
41
+ // assert.ok(stdout.includes('qunitx unknown command. Available options are:'));
42
+ // assert.ok(stdout.includes(printedHelpOutput));
43
+ // }
44
+ // });
@@ -0,0 +1,23 @@
1
+ import { module, test } from 'qunitx';
2
+ import { assertPassingTestCase, assertFailingTestCase, assertTAPResult } from '../helpers/assert-stdout.js';
3
+ import shell from '../helpers/shell.js';
4
+
5
+ module('--after script tests for browser mode', { concurrency: false }, (_hooks, moduleMetadata) => {
6
+ test('--after works when it doesnt need to be awaited', async (assert, testMetadata) => {
7
+ const { stdout } = await shell('node cli.js test/helpers/passing-tests.js --after=test/helpers/after-script-basic.js', { ...moduleMetadata, ...testMetadata });
8
+
9
+ assert.ok(stdout.includes('This is running from after script!!'));
10
+ assertPassingTestCase(assert, stdout, { debug: false, testNo: 1, moduleName: '{{moduleName}}' });
11
+ assertTAPResult(assert, stdout, { testCount: 3 });
12
+ });
13
+
14
+ test('--after works when it needs to be awaited', async (assert, testMetadata) => {
15
+ const { stdout } = await shell('node cli.js test/helpers/passing-tests.js --after=test/helpers/after-script-async.js', { ...moduleMetadata, ...testMetadata });
16
+
17
+ assert.ok(stdout.includes('This is running from after script!!'));
18
+ assert.ok(stdout.includes('After script result is written:'));
19
+ assert.ok(stdout.includes(JSON.stringify({ testCount: 3, failCount: 0, skipCount: 0, passCount: 3 }, null, 2)));
20
+ assertPassingTestCase(assert, stdout, { testNo: 1, moduleName: '{{moduleName}}' });
21
+ assertTAPResult(assert, stdout, { testCount: 3 });
22
+ });
23
+ });
@@ -0,0 +1,23 @@
1
+ import { module, test } from 'qunitx';
2
+ import { assertPassingTestCase, assertFailingTestCase, assertTAPResult } from '../helpers/assert-stdout.js';
3
+ import shell from '../helpers/shell.js';
4
+
5
+ module('--before script tests for browser mode', { concurrency: false }, (_hooks, moduleMetadata) => {
6
+ test('--before works when it doesnt need to be awaited', async (assert, testMetadata) => {
7
+ const { stdout } = await shell('node cli.js test/helpers/passing-tests.js --before=test/helpers/before-script-basic.js', { ...moduleMetadata, ...testMetadata });
8
+
9
+ assert.ok(stdout.includes('This is running from before script!!'));
10
+ assertPassingTestCase(assert, stdout, { testNo: 1, moduleName: '{{moduleName}}' });
11
+ assertTAPResult(assert, stdout, { testCount: 3 });
12
+ });
13
+
14
+ test('--before works it needs to be awaited', { concurrency: false }, async (assert, testMetadata) => {
15
+ const { stdout } = await shell('node cli.js test/helpers/passing-tests.js test/helpers/before-script-web-server-tests.js --before=test/helpers/before-script-async.js', { ...moduleMetadata, ...testMetadata });
16
+
17
+ assert.ok(stdout.includes('This is running from before script!!'));
18
+ assert.ok(stdout.includes('Starting before script with:'));
19
+ assertPassingTestCase(assert, stdout, { testNo: 1, moduleName: '{{moduleName}}' });
20
+ assertPassingTestCase(assert, stdout, { testNo: 4, moduleName: '{{moduleName}} Before script web server tests' });
21
+ assertTAPResult(assert, stdout, { testCount: 4 });
22
+ });
23
+ });
@@ -0,0 +1,6 @@
1
+ import { module, test } from 'qunitx';
2
+
3
+ // test('todo', async (t) => {
4
+ // t.true(true);
5
+ // });
6
+
@@ -0,0 +1,5 @@
1
+ import { module, test } from 'qunitx';
2
+
3
+ // test('todo', async (t) => {
4
+ // t.true(true);
5
+ // });
@@ -0,0 +1,2 @@
1
+ import "./after-test.js";
2
+ import "./before-test.js";
@@ -0,0 +1,6 @@
1
+ import { module, test } from 'qunitx';
2
+
3
+ // test('todo', async (t) => {
4
+ // t.true(true);
5
+ // });
6
+
@@ -0,0 +1,6 @@
1
+ import { module, test } from 'qunitx';
2
+
3
+ // test('todo', async (t) => {
4
+ // t.true(true);
5
+ // });
6
+
@@ -0,0 +1,6 @@
1
+ import { module, test } from 'qunitx';
2
+
3
+ // test('todo', async (t) => {
4
+ // t.true(true);
5
+ // });
6
+
@@ -0,0 +1,6 @@
1
+ import { module, test } from 'qunitx';
2
+
3
+ // test('todo', async (t) => {
4
+ // t.true(true);
5
+ // });
6
+
@@ -0,0 +1,13 @@
1
+ import fs from 'fs/promises';
2
+ import './after-script-basic.js';
3
+
4
+ export default async function(results) {
5
+ let resultsInString = JSON.stringify(results, null, 2);
6
+
7
+ await fs.rm(`${process.cwd()}/tmp/results.json`, { force: true, recursive: true });
8
+ await fs.writeFile(`${process.cwd()}/tmp/results.json`, resultsInString);
9
+
10
+ console.log('After script result is written:');
11
+ console.log(resultsInString);
12
+ }
13
+
@@ -0,0 +1 @@
1
+ console.log('This is running from after script!!');
@@ -0,0 +1,112 @@
1
+ export function assertStdout(assert, folderNames, options={ checkFailure: false, debug: false }) {
2
+ // folderNames.forEach((folder
3
+ }
4
+
5
+ export function assertPassingTestCase(assert, stdout, options={ moduleName: '{{moduleName}}', debug: false }) {
6
+ let { moduleName, debug } = options;
7
+
8
+ if (debug) {
9
+ assert.ok(new RegExp(`ok \. ${moduleName} | assert.ok works # (\d+ ms)`).test(stdout));
10
+ assert.ok(stdout.includes('resolving async test'));
11
+ assert.ok(/(.+)placeholder(.+)/g.test(stdout));
12
+ assert.ok(/(.+)anotherObject(.+)/g.test(stdout));
13
+ assert.ok(new RegExp(`ok \. ${moduleName} | async test finishes # (\d+ ms)`).test(stdout));
14
+ assert.ok(stdout.includes('calling deepEqual test case'));
15
+ // assert.ok(new RegExp(`ok ${testNo++} ${moduleName} | deepEqual true works # (\d+ ms)`).test(stdout));
16
+ } else {
17
+ assert.ok(new RegExp(`ok \. ${moduleName} | assert.ok works # (\d+ ms)`).test(stdout));
18
+ assert.ok(new RegExp(`ok \. ${moduleName} | async test finishes # (\d+ ms)`).test(stdout));
19
+ // assert.ok(new RegExp(`ok ${testNo++} ${moduleName} | deepEqual true works # (\d+ ms)`).test(stdout));
20
+ }
21
+ }
22
+
23
+ export function assertFailingTestCase(assert, stdout, options={ moduleName: '{{moduleName}}', debug: false }) {
24
+ let { moduleName, debug } = options;
25
+
26
+ if (debug) {
27
+ assert.ok(stdout.includes('calling assert true test case'));
28
+ assert.ok(stdout.includes('resolving async test'));
29
+ assert.ok(/(.+)placeholder(.+)/g.test(stdout));
30
+ assert.ok(/(.+)anotherObject(.+)/g.test(stdout));
31
+ } else {
32
+ assert.ok(!stdout.includes('calling assert true test case'));
33
+ assert.ok(!stdout.includes('resolving async test'));
34
+ assert.notOk(/(.+)placeholder(.+)/g.test(stdout));
35
+ assert.notOk(/(.+)anotherObject(.+)/g.test(stdout));
36
+
37
+ assert.ok(new RegExp(`not ok 2 ${moduleName} | async test finishes # (\d+ ms)␊
38
+ ---␊
39
+ name: 'Assertion #1'␊
40
+ actual: null␊
41
+ expected: null␊
42
+ message: 'Promise rejected during "async test finishes": wait is not a function'␊
43
+ stack: |-␊
44
+ TypeError: wait is not a function␊
45
+ at Object.<anonymous> (\S+:\d+:\d+)␊
46
+ at: '\S+:\d+:\d+'␊
47
+ ...␊
48
+ ---␊
49
+ name: 'Assertion #2'␊
50
+ actual: null␊
51
+ expected: null␊
52
+ message: 'Expected 4 assertions, but 1 were run'␊
53
+ stack: ' at Object.<anonymous> (\S+:\d+:\d+)'␊
54
+ at: '\S+:\d+:\d+'␊
55
+ ...`).test(stdout));
56
+ assert.ok(new RegExp(`not ok 3 ${moduleName} | runtime error output # (\d+ ms)
57
+ ---
58
+ name: 'Assertion #1'
59
+ actual: null
60
+ expected: true
61
+ message: null
62
+ stack: ' at Object.<anonymous> (\S+:\d+:\d+)'
63
+ at: '\S+:\d+:\d+'
64
+ ...
65
+ ---
66
+ name: 'Assertion #2'
67
+ actual: null
68
+ expected: null
69
+ message: >-
70
+ Died on test #2 at Object.<anonymous>
71
+ (\S+:\d+:\d+): Cannot
72
+ read property 'second' of undefined
73
+ stack: |-
74
+ TypeError: Cannot read property 'second' of undefined
75
+ at Object.<anonymous> (\S+:\d+:\d+)
76
+ at: '\S+:\d+:\d+'
77
+ ...
78
+ `).test(stdout));
79
+ assert.ok(new RegExp(`not ok 4 ${moduleName} | deepEqual true works # (\d+ ms)␊
80
+ ---␊
81
+ name: 'Assertion #1'␊
82
+ actual:␊
83
+ firstName: Izel␊
84
+ lastName: Nakri␊
85
+ expected:␊
86
+ firstName: Isaac␊
87
+ lastName: Nakri␊
88
+ message: null␊
89
+ stack: ' at Object.<anonymous> (\S+:\d+:\d+)'␊
90
+ at: '\S+:\d+:\d+'␊
91
+ ...␊`).test(stdout));
92
+ }
93
+ }
94
+
95
+ export function assertTAPResult(assert, stdout, options={ testCount: 0, failCount: 0 }) {
96
+ if (options.failCount) {
97
+ return assert.ok(new RegExp(`# pass ${options.testCount - options.failCount}
98
+ # skip 0
99
+ # fail (${options.failCount}|${options.failCount + 1})`).test(stdout));
100
+ }
101
+
102
+ assert.ok(new RegExp(`# pass ${options.testCount}
103
+ # skip 0
104
+ # fail 0`).test(stdout));
105
+ }
106
+
107
+ export default {
108
+ assertStdout,
109
+ assertPassingTestCase,
110
+ assertFailingTestCase,
111
+ assertTAPResult
112
+ }
@@ -0,0 +1,35 @@
1
+ import express from 'express';
2
+ import cors from "cors";
3
+ import kleur from 'kleur';
4
+ import bindServerToPort from '../../lib/setup/bind-server-to-port.js';
5
+ import './before-script-basic.js';
6
+ import QUnit from 'qunitx';
7
+
8
+ export default async function(config) {
9
+ console.log('Starting before script with:');
10
+
11
+ let hasServerRunning = !!config.expressApp;
12
+
13
+ config.expressApp = config.expressApp || express();
14
+ config.expressApp.use(cors());
15
+ config.expressApp.get("/films", (req, res) => {
16
+ console.log('req received');
17
+ res.json({ film: "responsed correctly" });
18
+ });
19
+ config.expressApp.get("/movies/too-big-to-fail", (req, res) => {
20
+ res.json({ movie: "is too-big-to-fail" });
21
+ });
22
+
23
+ if (!hasServerRunning) {
24
+ console.log('DOESNT HAVE SERVER RUNNING');
25
+ let server = await bindServerToPort(config.expressApp, config);
26
+
27
+ QUnit.config.port = config.port;
28
+ console.log(`Web server started on port ${QUnit.config.port}`);
29
+ }
30
+ }
31
+
32
+ function wait(duration) {
33
+ return new Promise((resolve) => setTimeout(() => { resolve() }, duration));
34
+ }
35
+
@@ -0,0 +1 @@
1
+ console.log('This is running from before script!!');
@@ -0,0 +1,28 @@
1
+ import { module, test } from 'qunitx';
2
+
3
+ module('{{moduleName}} Before script web server tests', function(hooks) {
4
+ test('assert true works', async function (assert) {
5
+ let json;
6
+ try {
7
+ let port = window.QUnit.config.port || location.port;
8
+
9
+ await wait(250);
10
+
11
+ let res = await fetch(`http://127.0.0.1:${port}/films`);
12
+ json = await res.json();
13
+ } catch (err) {
14
+ console.log('FETCH ERR', err);
15
+ console.log(err.cause);
16
+ }
17
+
18
+ assert.deepEqual(json, { film: 'responsed correctly' });
19
+ });
20
+
21
+ // test('async test finishes', async function (assert) {
22
+
23
+ // });
24
+ });
25
+
26
+ function wait(duration) {
27
+ return new Promise((resolve) => setTimeout(() => { resolve() }, duration));
28
+ }
@@ -0,0 +1,49 @@
1
+ import { module, test } from 'qunitx';
2
+
3
+ module('{{moduleName}} Failing Tests', function(hooks) {
4
+ test('assert true works', function (assert) {
5
+ assert.expect(3);
6
+ assert.ok(true);
7
+ console.log('calling assert true test case');
8
+ assert.equal(true, true);
9
+ assert.equal(null, null);
10
+ });
11
+
12
+ test('async test finishes', async function (assert) {
13
+ assert.expect(4);
14
+
15
+ const wait = () => new Promise((resolve, reject) => {
16
+ window.setTimeout(() => {
17
+ console.log('resolving async test');
18
+ console.log({
19
+ moduleName: 'called resolved async test with object',
20
+ placeholder: 1000,
21
+ anotherObject: {
22
+ firstName: 'Izel',
23
+ createdAt: new Date('2021-03-06')
24
+ }
25
+ });
26
+ resolve(true);
27
+ }, 50);
28
+ });
29
+ const result = await wait();
30
+
31
+ assert.ok(true);
32
+ assert.equal(false, result);
33
+ assert.equal(null, null);
34
+ });
35
+
36
+ test('runtime error output', function (assert) {
37
+ let smt = {};
38
+
39
+ assert.equal(undefined, true);
40
+ assert.deepEqual(smt.first.second, {});
41
+ });
42
+
43
+ test('deepEqual true works', function (assert) {
44
+ const me = { firstName: 'Izel', lastName: 'Nakri' };
45
+
46
+ console.log('calling deepEqual test case');
47
+ assert.deepEqual(me, { firstName: 'Isaac', lastName: 'Nakri' });
48
+ });
49
+ });
@@ -0,0 +1,49 @@
1
+ import { module, test } from 'qunitx';
2
+
3
+ module('{{moduleName}} Failing Tests', function(hooks) {
4
+ test('assert true works', function (assert) {
5
+ assert.expect(3);
6
+ assert.ok(true);
7
+ console.log('calling assert true test case');
8
+ assert.equal(true, true);
9
+ assert.equal(null, null);
10
+ });
11
+
12
+ test('async test finishes', async function (assert) {
13
+ assert.expect(4);
14
+
15
+ const wait = () => new Promise((resolve, reject) => {
16
+ window.setTimeout(() => {
17
+ console.log('resolving async test');
18
+ console.log({
19
+ moduleName: 'called resolved async test with object',
20
+ placeholder: 1000,
21
+ anotherObject: {
22
+ firstName: 'Izel',
23
+ createdAt: new Date('2021-03-06')
24
+ }
25
+ });
26
+ resolve(true);
27
+ }, 50);
28
+ });
29
+ const result = await wait();
30
+
31
+ assert.ok(true);
32
+ assert.equal(false, result);
33
+ assert.equal(null, null);
34
+ });
35
+
36
+ test('runtime error output', function (assert) {
37
+ let smt = {};
38
+
39
+ assert.equal(undefined, true);
40
+ assert.deepEqual(smt.first.second, {});
41
+ });
42
+
43
+ test('deepEqual true works', function (assert) {
44
+ const me = { firstName: 'Izel', lastName: 'Nakri' };
45
+
46
+ console.log('calling deepEqual test case');
47
+ assert.deepEqual(me, { firstName: 'Isaac', lastName: 'Nakri' });
48
+ });
49
+ });