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,7 @@
1
+ version: 2
2
+ updates:
3
+ # Maintain dependencies for GitHub Actions
4
+ - package-ecosystem: "github-actions"
5
+ directory: "/"
6
+ schedule:
7
+ interval: "daily"
@@ -0,0 +1,36 @@
1
+ name: docker-based-ci
2
+ on: push
3
+ jobs:
4
+ test:
5
+ runs-on: ubuntu-latest
6
+ steps:
7
+ - name: Checkout
8
+ uses: actions/checkout@v3
9
+ - name: Set ENV variables
10
+ run: |
11
+ echo "REGISTRY=ghcr.io" >> $GITHUB_ENV
12
+ echo "REPO_OWNER=$(echo ${GITHUB_REPOSITORY%/*})" >> $GITHUB_ENV
13
+ echo "REPO_NAME=$(echo ${GITHUB_REPOSITORY#*/})" >> $GITHUB_ENV
14
+ echo "BRANCH_NAME=$(echo ${GITHUB_REF#refs/heads/} | tr / -)" >> $GITHUB_ENV
15
+ echo "DOCKER_TAG=$(echo ${GITHUB_REPOSITORY#*/}):$(echo ${GITHUB_REF#refs/heads/} | tr / -)" >> $GITHUB_ENV
16
+ - name: Set up Docker Buildx
17
+ uses: docker/setup-buildx-action@v2.9.0
18
+ with:
19
+ install: true
20
+ - name: Login to GitHub Container Registry
21
+ uses: docker/login-action@v2.2.0
22
+ with:
23
+ registry: ${{env.REGISTRY}}
24
+ username: ${{env.REPO_OWNER}}
25
+ password: ${{secrets.CR_PAT}}
26
+ - name: Build and push
27
+ uses: docker/build-push-action@v4.1.1
28
+ with:
29
+ context: .
30
+ file: ./Dockerfile
31
+ push: true
32
+ tags: ${{env.REGISTRY}}/${{env.REPO_OWNER}}/${{env.DOCKER_TAG}}
33
+ cache-from: type=gha
34
+ cache-to: type=gha,mode=max
35
+ - name: Execute tests
36
+ run: docker run -t --entrypoint="npm" ${REGISTRY}/${REPO_OWNER}/${DOCKER_TAG} run test
package/CHANGELOG.md CHANGED
@@ -4,6 +4,22 @@ All notable changes to this project will be documented in this file. Dates are d
4
4
 
5
5
  Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
6
6
 
7
+ #### [0.1.0](https://github.com/izelnakri/qunitx-cli/compare/0.0.3...0.1.0)
8
+
9
+ - pkg upgrades & github CI [`7a33c07`](https://github.com/izelnakri/qunitx-cli/commit/7a33c07ef9c7b404458ac8b46f97c11009fe32fa)
10
+ - remove --browser flag from help [`011c5ae`](https://github.com/izelnakri/qunitx-cli/commit/011c5aecb1e293bb57aa396d7ceac0fca349298f)
11
+ - add TODO [`35a5121`](https://github.com/izelnakri/qunitx-cli/commit/35a512135d9b5abab740bfde9ae6ecb1781ab26b)
12
+
13
+ #### [0.0.3](https://github.com/izelnakri/qunitx-cli/compare/0.0.2...0.0.3)
14
+
15
+ > 13 July 2023
16
+
17
+ - Release 0.0.3 [`0379477`](https://github.com/izelnakri/qunitx-cli/commit/037947750cc372bdd5c45389d78131bd0b8fa51e)
18
+ - built the foundation for development [`569d860`](https://github.com/izelnakri/qunitx-cli/commit/569d8606b75287aceeaaf0b711139650182cd6c4)
19
+
7
20
  #### 0.0.2
8
21
 
22
+ > 13 July 2023
23
+
24
+ - Release 0.0.2 [`73f444d`](https://github.com/izelnakri/qunitx-cli/commit/73f444d385dd8c08188f5a992f172bd5ff898d89)
9
25
  - init [`4d2ac8f`](https://github.com/izelnakri/qunitx-cli/commit/4d2ac8fd98ce7a4c988f9036064a6ef592b55f8f)
package/Dockerfile ADDED
@@ -0,0 +1,24 @@
1
+ FROM node:20.4.0-slim
2
+
3
+ ENV PUPPETEER_SKIP_DOWNLOAD=true CHROME_BIN=/usr/bin/google-chrome-stable
4
+
5
+ RUN apt-get update \
6
+ && apt-get install -y wget gnupg \
7
+ && wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \
8
+ && sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list' \
9
+ && apt-get update \
10
+ && apt-get install -y git libxshmfence-dev google-chrome-stable --no-install-recommends \
11
+ && rm -rf /var/lib/apt/lists/*
12
+
13
+ WORKDIR /code/
14
+
15
+ ADD package.json package-lock.json /code/
16
+
17
+ RUN npm install
18
+
19
+ ADD lib /code/lib
20
+ ADD vendor /code/vendor
21
+ ADD test /code/test
22
+ ADD . /code/
23
+
24
+ ENTRYPOINT "/bin/bash"
package/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 Izel Nakri and other contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/TODO ADDED
@@ -0,0 +1,90 @@
1
+ - "$ qunitx sanity-test.ts" made redundant due to (node --test mode) this should impact dependencies and internal modules
2
+ - Implement other test cases in deno
3
+
4
+ Shim dir structure should be: shims/nodejs/ shims/deno shims/browser
5
+ Make package.json point to them correctly
6
+ Make the package so esbuild build so esbuild builds when qunitx is vendored(if it needs to)
7
+
8
+ Turn import { module, test } from '../../shims/nodejs.js' to import { module, test } from 'qunitx'; For this to happen browser bundler should pick up actual qunit
9
+
10
+ Combine nix with Docker for faster container builds
11
+
12
+ - also watch subdependencies on browser mode (-- how? investigate esbuild watch)
13
+ - maybe make browser tests per file loading <script>, also could add asset maps maybe if puppeteer supports, this could fix initial "qf" bug
14
+
15
+ implement and test require and timeout flags
16
+ implement concurrency
17
+
18
+ fix watcher for file removals make the logic smarter
19
+
20
+ allow passing absolutePaths(maybe)
21
+
22
+ - globs: test dynamically added file is watched on global input configuration | also check added files on watch gets put to config.fileOrFolderInputs
23
+ currently parse-fs-inputs might be less performant on big folders(?) dependending on how watch is implemented
24
+ - coverage
25
+ watch parsed files from html(?)
26
+
27
+
28
+ $ qunitx some-test --browser | default html doesnt match with $ qunitx init and also no html mode should be there
29
+
30
+ try this: $ npx ava --tap | npx tap-difflet
31
+ or this: $ npx ava --tap | npx faucet
32
+
33
+ research mocha reporter(TAP > reporters | json stream metada then it consumes this metadata(how?))
34
+ example good reporters: spec(reporter), dot, tap, landing strip(interesting instead put percentage), jest
35
+
36
+ esbuild ./tmp/test/passing-tests.js --bundle > test.js
37
+ parse qunitx in the package.json for config
38
+
39
+ failFast and babelOptions?
40
+ files(and to ignore), require, timeout
41
+ concurrencyStrategies
42
+
43
+ add node and browser options
44
+ add functionality to execute only one test
45
+ add reporters
46
+
47
+ pass timezone: https://stackoverflow.com/questions/16448754/how-to-use-a-custom-time-in-browser-to-test-for-client-vs-server-time-difference/39533934#39533934
48
+ = qunitx --timezone="US/Pacific"
49
+
50
+ QUnit regex filters
51
+
52
+ Jest Notes
53
+ ==========
54
+ TestSequencer
55
+ - this failed in the past? run first
56
+ - when file changed latest
57
+ - this test run in the past and was long? long tests run first
58
+ - file size
59
+
60
+ TestScheduler
61
+ - schedule across threads
62
+ - reporters
63
+ - dont spawn many threads if total test count is small
64
+ jest-runner/jest-puppeteer(check this)
65
+
66
+ read jest-worker/worker_thread implementation
67
+
68
+
69
+ check if jest-qunit exists
70
+
71
+ jest-runtime(creates VM context)
72
+ allows module mocking, custom require implementation, also does transforms
73
+ runs the tests
74
+ transform is sync in jest(dep tracking problem)
75
+
76
+ TestResult / Repoter
77
+ - all data has to be json serializable for threads
78
+ - stack trace of errors
79
+ - how many assertions
80
+
81
+ AggregatedRestResult[]
82
+ - finished test case, how long, each assertion
83
+ - check jest runners
84
+
85
+ qunitx init
86
+
87
+
88
+ write test metadata(each test) if flag is provided
89
+
90
+ markdown reporter(interesting: https://mochajs.org/#markdown)
package/build.js CHANGED
@@ -1 +1,54 @@
1
- console.log('TODO: build.js');
1
+ import fs from 'fs/promises';
2
+
3
+ let [qunitJS, qunitCSS, _] = await Promise.all([
4
+ fs.readFile('./node_modules/qunit/qunit/qunit.js'),
5
+ fs.readFile('./node_modules/qunit/qunit/qunit.css'),
6
+ fs.mkdir('./vendor', { recursive: true })
7
+ ]);
8
+
9
+ let newQUnit = qunitJS.toString().replace(
10
+ 'start: function start(count) {',
11
+ `reset: function() {
12
+ ProcessingQueue.finished = false;
13
+ globalStartCalled = false;
14
+ runStarted = false;
15
+
16
+ config.queue.length = 0;
17
+ config.modules.length = 0;
18
+ config.autostart = false;
19
+
20
+ Object.assign(config.stats, { total: 0, passed: 0, failed: 0, skipped: 0, todo: 0 });
21
+
22
+ [
23
+ "started", "updateRate", "filter", "depth", "current",
24
+ "pageLoaded", "timeoutHandler", "timeout", "pollution"
25
+ ].forEach( ( key ) => delete config[ key ] );
26
+
27
+ const suiteReport = config.currentModule.suiteReport;
28
+
29
+ suiteReport.childSuites.length = 0;
30
+ delete suiteReport._startTime;
31
+ delete suiteReport._endTime;
32
+
33
+ config.modules.push( config.currentModule );
34
+ },
35
+ start: function start(count) {`);
36
+
37
+ await Promise.all([
38
+ fs.writeFile('./vendor/qunit.js', newQUnit),
39
+ fs.writeFile('./vendor/qunit.css', qunitCSS),
40
+ createPackageJSONIfNotExists()
41
+ ]);
42
+
43
+ async function createPackageJSONIfNotExists() {
44
+ try {
45
+ await fs.stat('./vendor/package.json');
46
+
47
+ return true;
48
+ } catch (error) {
49
+ await fs.writeFile('./vendor/package.json', JSON.stringify({
50
+ name: 'qunitx-vendor',
51
+ version: '0.0.1'
52
+ }));
53
+ }
54
+ }
package/cli.js CHANGED
@@ -1,2 +1,25 @@
1
1
  #!/usr/bin/env -S TS_NODE_COMPILER_OPTIONS='{"module":"ES2020"}' node --loader ts-node/esm/transpile-only
2
- console.log('Future QUnitX CLI');
2
+ import process from 'node:process';
3
+ import displayHelpOutput from './lib/commands/help.js';
4
+ import initializeProject from './lib/commands/init.js';
5
+ import generateTestFiles from './lib/commands/generate.js';
6
+ import run from './lib/commands/run.js';
7
+ import setupConfig from './lib/setup/config.js';
8
+
9
+ process.title = 'qunitx';
10
+
11
+ (async () => {
12
+ if (!process.argv[2]) {
13
+ return await displayHelpOutput();
14
+ } else if (['help', 'h', 'p', 'print'].includes(process.argv[2])) {
15
+ return await displayHelpOutput();
16
+ } else if (['new', 'n', 'g', 'generate'].includes(process.argv[2])) {
17
+ return await generateTestFiles();
18
+ } else if (['init'].includes(process.argv[2])) {
19
+ return await initializeProject();
20
+ }
21
+
22
+ let config = await setupConfig();
23
+
24
+ return await run(config);
25
+ })();
@@ -0,0 +1,6 @@
1
+ export default {
2
+ output: 'tmp',
3
+ timeout: 20000,
4
+ failFast: false,
5
+ port: 1234
6
+ }
@@ -0,0 +1,15 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <meta name="viewport" content="width=device-width">
6
+ <title>{{applicationName}} Tests</title>
7
+ <link href="../node_modules/qunitx/vendor/qunit.css" rel="stylesheet">
8
+ </head>
9
+ <body>
10
+ <div id="qunit"></div>
11
+ <div id="qunit-fixture"></div>
12
+
13
+ {{content}}
14
+ </body>
15
+ </html>
@@ -0,0 +1,109 @@
1
+ {
2
+ "compilerOptions": {
3
+ /* Visit https://aka.ms/tsconfig to read more about this file */
4
+
5
+ /* Projects */
6
+ // "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */
7
+ // "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */
8
+ // "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */
9
+ // "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */
10
+ // "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
11
+ // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
12
+
13
+ /* Language and Environment */
14
+ "target": "es2016", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
15
+ // "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
16
+ // "jsx": "preserve", /* Specify what JSX code is generated. */
17
+ // "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */
18
+ // "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
19
+ // "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */
20
+ // "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */
21
+ // "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */
22
+ // "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */
23
+ // "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
24
+ // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
25
+ // "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
26
+
27
+ /* Modules */
28
+ "module": "NodeNext", /* Specify what module code is generated. */
29
+ // "rootDir": ".", /* Specify the root folder within your source files. */
30
+ "moduleResolution": "NodeNext", /* Specify how TypeScript looks up a file from a given module specifier. */
31
+ // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
32
+ // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
33
+ // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
34
+ // "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */
35
+ // "types": [], /* Specify type package names to be included without being referenced in a source file. */
36
+ // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
37
+ // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */
38
+ // "allowImportingTsExtensions": true, /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */
39
+ // "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */
40
+ // "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */
41
+ // "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */
42
+ // "resolveJsonModule": true, /* Enable importing .json files. */
43
+ // "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */
44
+ // "noResolve": true, /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. */
45
+
46
+ /* JavaScript Support */
47
+ // "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */
48
+ // "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */
49
+ // "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */
50
+
51
+ /* Emit */
52
+ // "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
53
+ // "declarationMap": true, /* Create sourcemaps for d.ts files. */
54
+ // "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
55
+ // "sourceMap": true, /* Create source map files for emitted JavaScript files. */
56
+ // "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
57
+ // "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
58
+ // "outDir": "./", /* Specify an output folder for all emitted files. */
59
+ // "removeComments": true, /* Disable emitting comments. */
60
+ // "noEmit": true, /* Disable emitting files from a compilation. */
61
+ // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
62
+ // "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types. */
63
+ // "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */
64
+ // "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */
65
+ // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
66
+ // "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */
67
+ // "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */
68
+ // "newLine": "crlf", /* Set the newline character for emitting files. */
69
+ // "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */
70
+ // "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */
71
+ // "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
72
+ // "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */
73
+ // "declarationDir": "./", /* Specify the output directory for generated declaration files. */
74
+ // "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */
75
+
76
+ /* Interop Constraints */
77
+ // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
78
+ // "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */
79
+ // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
80
+ "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
81
+ // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
82
+ "forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
83
+
84
+ /* Type Checking */
85
+ "strict": true, /* Enable all strict type-checking options. */
86
+ // "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */
87
+ // "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */
88
+ // "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
89
+ // "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */
90
+ // "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */
91
+ // "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */
92
+ // "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */
93
+ // "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */
94
+ // "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */
95
+ // "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */
96
+ // "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */
97
+ // "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
98
+ // "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */
99
+ // "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */
100
+ // "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */
101
+ // "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */
102
+ // "allowUnusedLabels": true, /* Disable error reporting for unused labels. */
103
+ // "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */
104
+
105
+ /* Completeness */
106
+ // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
107
+ "skipLibCheck": true /* Skip type checking all .d.ts files. */
108
+ }
109
+ }
@@ -0,0 +1,25 @@
1
+ import { module, test } from 'qunitx';
2
+
3
+ module('{{moduleName}}', function(hooks) {
4
+ test('assert true works', function (assert) {
5
+ assert.expect(3);
6
+ assert.ok(true);
7
+ assert.equal(true, true);
8
+ assert.deepEqual({}, {});
9
+ });
10
+
11
+ test('async test finishes', async function (assert) {
12
+ assert.expect(3);
13
+
14
+ let wait = () => new Promise((resolve, reject) => {
15
+ setTimeout(() => resolve(true), 50);
16
+ });
17
+ let result = await wait();
18
+
19
+ assert.ok(true);
20
+ assert.equal(true, result);
21
+
22
+ await wait();
23
+ assert.equal(true, result);
24
+ });
25
+ });
@@ -0,0 +1,33 @@
1
+ import fs from 'node:fs/promises';
2
+ import { dirname } from 'node:path';
3
+ import { fileURLToPath } from 'node:url';
4
+ import kleur from 'kleur';
5
+ import findProjectRoot from '../utils/find-project-root.js';
6
+ import pathExists from '../utils/path-exists.js';
7
+
8
+ const __dirname = dirname(fileURLToPath(import.meta.url));
9
+
10
+ export default async function() {
11
+ let projectRoot = await findProjectRoot();
12
+ let moduleName = process.argv[3]; // TODO: classify this maybe in future
13
+ let path = process.argv[3].endsWith('.js') || process.argv[3].endsWith('.ts')
14
+ ? `${projectRoot}/${process.argv[3]}`
15
+ : `${projectRoot}/${process.argv[3]}.js`;
16
+
17
+ if (await pathExists(path)) {
18
+ return console.log(`${path} already exists!`);
19
+ }
20
+
21
+ let testJSContent = await fs.readFile(`${__dirname}/../boilerplates/test.js`);
22
+ let targetFolderPaths = path.split('/');
23
+
24
+ targetFolderPaths.pop();
25
+
26
+ await fs.mkdir(targetFolderPaths.join('/'), { recursive: true });
27
+ await fs.writeFile(
28
+ path,
29
+ testJSContent.toString().replace('{{moduleName}}', moduleName)
30
+ );
31
+
32
+ console.log(kleur.green(`${path} written`));
33
+ }
@@ -0,0 +1,37 @@
1
+ import fs from 'node:fs/promises';
2
+ import { dirname } from 'node:path';
3
+ import { fileURLToPath } from 'node:url';
4
+ import kleur from 'kleur';
5
+
6
+ const __dirname = dirname(fileURLToPath(import.meta.url));
7
+ const highlight = (text) => kleur.magenta().bold(text);
8
+ const color = (text) => kleur.blue(text);
9
+
10
+
11
+ export default async function() {
12
+ const config = JSON.parse((await fs.readFile(`${__dirname}/../../package.json`)));
13
+
14
+ console.log(`${highlight("[qunitx v" + config.version + "] Usage:")} qunitx ${color('[targets] --$flags')}
15
+
16
+ ${highlight("Input options:")}
17
+ - File: $ ${color('qunitx test/foo.js')}
18
+ - Folder: $ ${color('qunitx test/login')}
19
+ - Globs: $ ${color('qunitx test/**/*-test.js')}
20
+ - Combination: $ ${color('qunitx test/foo.js test/bar.js test/*-test.js test/logout')}
21
+
22
+ ${highlight("Optional flags:")}
23
+ ${color('--debug')} : print console output when tests run in browser
24
+ ${color('--watch')} : run the target file or folders, watch them for continuous run and expose http server under localhost
25
+ ${color('--timeout')} : change default timeout per test case
26
+ ${color('--output')} : folder to distribute built qunitx html and js that a webservers can run[default: tmp]
27
+ ${color('--failFast')} : run the target file or folders with immediate abort if a single test fails
28
+ ${color('--before')} : run a script before the tests(i.e start a new web server before tests)
29
+ ${color('--after')} : run a script after the tests(i.e save test results to a file)
30
+
31
+ ${highlight("Example:")} $ ${color('qunitx test/foo.ts app/e2e --debug --watch --before=scripts/start-new-webserver.js --after=scripts/write-test-results.js')}
32
+
33
+ ${highlight("Commands:")}
34
+ ${color('$ qunitx init')} # Bootstraps qunitx base html and add qunitx config to package.json if needed
35
+ ${color('$ qunitx new $testFileName')} # Creates a qunitx test file
36
+ `);
37
+ }
@@ -0,0 +1,70 @@
1
+ import fs from 'node:fs/promises';
2
+ import path, { dirname } from 'node:path';
3
+ import { fileURLToPath } from 'node:url';
4
+ import findProjectRoot from '../utils/find-project-root.js';
5
+ import pathExists from '../utils/path-exists.js';
6
+ import defaultProjectConfigValues from '../boilerplates/default-project-config-values.js';
7
+
8
+ const __dirname = dirname(fileURLToPath(import.meta.url));
9
+
10
+ export default async function() {
11
+ let projectRoot = await findProjectRoot();
12
+ let oldPackageJSON = JSON.parse(await fs.readFile(`${projectRoot}/package.json`));
13
+ let htmlPaths = process.argv.slice(2).reduce((result, arg) => {
14
+ if (arg.endsWith('.html')) {
15
+ result.push(arg);
16
+ }
17
+
18
+ return result;
19
+ }, oldPackageJSON.qunitx && oldPackageJSON.qunitx.htmlPaths ? oldPackageJSON.qunitx.htmlPaths : []);
20
+ let newQunitxConfig = Object.assign(
21
+ defaultProjectConfigValues,
22
+ htmlPaths.length > 0 ? { htmlPaths } : { htmlPaths: ['test/tests.html'] },
23
+ oldPackageJSON.qunitx
24
+ );
25
+
26
+ await Promise.all([
27
+ writeTestsHTML(projectRoot, newQunitxConfig, oldPackageJSON),
28
+ rewritePackageJSON(projectRoot, newQunitxConfig, oldPackageJSON),
29
+ writeTSConfigIfNeeded(projectRoot)
30
+ ]);
31
+ }
32
+
33
+ async function writeTestsHTML(projectRoot, newQunitxConfig, oldPackageJSON) {
34
+ let testHTMLTemplateBuffer = await fs.readFile(`${__dirname}/../boilerplates/setup/tests.hbs`);
35
+
36
+ return await Promise.all(newQunitxConfig.htmlPaths.map(async (htmlPath) => {
37
+ let targetPath = `${projectRoot}/${htmlPath}`;
38
+ if (await pathExists(targetPath)) {
39
+ return console.log(`${htmlPath} already exists`);
40
+ } else {
41
+ let targetDirectory = path.dirname(targetPath);
42
+ let targetOutputPath = path.relative(targetDirectory, `${projectRoot}/${newQunitxConfig.output}/tests.js`);
43
+ let testHTMLTemplate = testHTMLTemplateBuffer
44
+ .toString()
45
+ .replace('{{applicationName}}', oldPackageJSON.name);
46
+
47
+ await fs.mkdir(targetDirectory, { recursive: true });
48
+ await fs.writeFile(targetPath, testHTMLTemplate);
49
+
50
+ console.log(`${targetPath} written`);
51
+ }
52
+ }));
53
+ }
54
+
55
+ async function rewritePackageJSON(projectRoot, newQunitxConfig, oldPackageJSON) {
56
+ let newPackageJSON = Object.assign(oldPackageJSON, { qunitx: newQunitxConfig });
57
+
58
+ await fs.writeFile(`${projectRoot}/package.json`, JSON.stringify(newPackageJSON, null, 2));
59
+ }
60
+
61
+ async function writeTSConfigIfNeeded(projectRoot) {
62
+ let targetPath = `${projectRoot}/tsconfig.json`;
63
+ if (!(await pathExists(targetPath))) {
64
+ let tsConfigTemplateBuffer = await fs.readFile(`${__dirname}/../boilerplates/setup/tsconfig.json`);
65
+
66
+ await fs.writeFile(targetPath, tsConfigTemplateBuffer);
67
+
68
+ console.log(`${targetPath} written`);
69
+ }
70
+ }