sxy-test-runner 1.0.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 (107) hide show
  1. package/dist/cli/index.js +33 -0
  2. package/dist/cli/init.js +170 -0
  3. package/dist/cli/init.unitTest.js +0 -0
  4. package/dist/cli/lib/addBasePath.js +15 -0
  5. package/dist/cli/lib/addBasePath.unitTest.js +31 -0
  6. package/dist/cli/lib/addExports.js +12 -0
  7. package/dist/cli/lib/addExports.unitTest.js +29 -0
  8. package/dist/cli/lib/applyConfigDefaults.js +41 -0
  9. package/dist/cli/lib/applyConfigDefaults.unitTest.js +25 -0
  10. package/dist/cli/lib/buildDependencyTree.js +32 -0
  11. package/dist/cli/lib/buildDependencyTree.unitTest.js +15 -0
  12. package/dist/cli/lib/buildDependencyTrees.js +34 -0
  13. package/dist/cli/lib/buildDependencyTrees.unitTest.js +17 -0
  14. package/dist/cli/lib/defaultConfig.js +22 -0
  15. package/dist/cli/lib/defaultConfig.test.js +7 -0
  16. package/dist/cli/lib/doUserSetup.js +30 -0
  17. package/dist/cli/lib/doUserSetup.unitTest.js +39 -0
  18. package/dist/cli/lib/doUserTeardown.js +30 -0
  19. package/dist/cli/lib/doUserTeardown.unitTest.js +39 -0
  20. package/dist/cli/lib/findTestFiles.js +24 -0
  21. package/dist/cli/lib/findTestFiles.unitTest.js +22 -0
  22. package/dist/cli/lib/getAllowedFlags.js +11 -0
  23. package/dist/cli/lib/getAllowedFlags.unitTest.js +20 -0
  24. package/dist/cli/lib/globArgCombine.js +1 -0
  25. package/dist/cli/lib/globArgCombine.unitTest.js +18 -0
  26. package/dist/cli/lib/injectProperties.js +11 -0
  27. package/dist/cli/lib/injectProperties.unitTest.js +75 -0
  28. package/dist/cli/lib/load.js +3 -0
  29. package/dist/cli/lib/load.unitTest.js +7 -0
  30. package/dist/cli/lib/loadConfig.js +21 -0
  31. package/dist/cli/lib/loadConfig.unitTest.js +15 -0
  32. package/dist/cli/lib/loadTestFile.js +75 -0
  33. package/dist/cli/lib/loadTestFile.unitTest.js +45 -0
  34. package/dist/cli/lib/loadTestFileStatic.js +40 -0
  35. package/dist/cli/lib/loadTestFileStatic.unitTest.js +29 -0
  36. package/dist/cli/lib/parseCommandLineArguments.js +57 -0
  37. package/dist/cli/lib/parseCommandLineArguments.unitTest.js +21 -0
  38. package/dist/cli/lib/parseDescribe.js +88 -0
  39. package/dist/cli/lib/parseDescribe.unitTest.js +17 -0
  40. package/dist/cli/lib/parseItsFromDescribe.js +115 -0
  41. package/dist/cli/lib/processWatchEvent.js +0 -0
  42. package/dist/cli/lib/processWatchEvent.unitTest.js +7 -0
  43. package/dist/cli/lib/reservedExportKeys.js +1 -0
  44. package/dist/cli/lib/reservedExportKeys.unitTest.js +7 -0
  45. package/dist/cli/lib/runDescribe.js +29 -0
  46. package/dist/cli/lib/runDescribe.old copy.js +115 -0
  47. package/dist/cli/lib/runDescribe.old.js +115 -0
  48. package/dist/cli/lib/runDescribe.old.unitTest.js +440 -0
  49. package/dist/cli/lib/runDescribe.unitTest.js +287 -0
  50. package/dist/cli/lib/runDescribeParseIts.js +87 -0
  51. package/dist/cli/lib/runDescribeParseIts.unitTest.js +0 -0
  52. package/dist/cli/lib/runDescribeRun.js +59 -0
  53. package/dist/cli/lib/runDescribeRun.unitTest.js +293 -0
  54. package/dist/cli/lib/runDescribeRunIts.js +56 -0
  55. package/dist/cli/lib/runDescribeRunIts.unitTest.js +0 -0
  56. package/dist/cli/lib/runIt.js +79 -0
  57. package/dist/cli/lib/runIt.unitTest.js +294 -0
  58. package/dist/cli/lib/runTasks.js +42 -0
  59. package/dist/cli/lib/runTasks.unitTest.js +30 -0
  60. package/dist/cli/lib/runTest-old.js +159 -0
  61. package/dist/cli/lib/runTest-old.unitTest.js +183 -0
  62. package/dist/cli/lib/runTest.js +71 -0
  63. package/dist/cli/lib/runTest.unitTest.js +269 -0
  64. package/dist/cli/lib/runTests.js +137 -0
  65. package/dist/cli/lib/runTests.unitTest.js +59 -0
  66. package/dist/cli/lib/showTestLoadingError.js +22 -0
  67. package/dist/cli/lib/showTestLoadingError.unitTest.js +25 -0
  68. package/dist/cli/lib/showTestResult.js +87 -0
  69. package/dist/cli/lib/showTestResult.unitTest.js +180 -0
  70. package/dist/cli/lib/timeProfier.js +7 -0
  71. package/dist/cli/lib/validateConfig.js +29 -0
  72. package/dist/cli/lib/validateConfig.unitTest.js +22 -0
  73. package/dist/cli/lib/watchFiles.js +1 -0
  74. package/dist/cli/lib/watchFiles.unitTest.js +48 -0
  75. package/dist/cli/lib/watchFilesAndRunTests.js +2 -0
  76. package/dist/cli/lib/watchFilesAndRunTests.unitTest.js +129 -0
  77. package/dist/cli/lib/watchFilesAndRunTestsChokidar.js +142 -0
  78. package/dist/cli/lib/watchFilesAndRunTestsChokidar.unitTest.js +133 -0
  79. package/dist/cli/lib/watchFilesAndRunTestsNodeWatch.js +162 -0
  80. package/dist/cli/lib/watchFilesAndRunTestsNodeWatch.unitTest.js +131 -0
  81. package/dist/cli/lib/watchFilesChokidar.js +56 -0
  82. package/dist/cli/lib/watchFilesChokidar.unitTest.js +85 -0
  83. package/dist/cli/lib/watchFilesNodeWatch.js +42 -0
  84. package/dist/cli/lib/watchFilesNodeWatch.unitTest.js +48 -0
  85. package/dist/cli/once.js +47 -0
  86. package/dist/cli/once.unitTest.js +39 -0
  87. package/dist/cli/watch.js +100 -0
  88. package/dist/cli/watch.unitTest.js +117 -0
  89. package/dist/config.js +7 -0
  90. package/dist/describe-old.js +257 -0
  91. package/dist/describe-old.unitTest.js +21 -0
  92. package/dist/describe.js +24 -0
  93. package/dist/describe.unitTest.js +27 -0
  94. package/dist/exported.eslintrc.js +7 -0
  95. package/dist/index.js +1 -0
  96. package/dist/indexNumberToLetters.js +13 -0
  97. package/dist/load.js +3 -0
  98. package/dist/output.js +17 -0
  99. package/dist/testing/example.test.js +26 -0
  100. package/dist/testing/example2.test.js +19 -0
  101. package/dist/testing/example3.test.js +16 -0
  102. package/dist/testing/importTimeTarget.js +9 -0
  103. package/dist/testing/importTimeTarget2.js +11 -0
  104. package/dist/testing/importTimeTest.js +8 -0
  105. package/dist/testsState.js +4 -0
  106. package/dist/timeProfiling.js +9 -0
  107. package/package.json +68 -0
@@ -0,0 +1,24 @@
1
+ import { loadConfig as sxyLoadConfig, createTimeProfiler } from 'sxy-dev-tools';
2
+ import { packageName, cliName, configFileName, configLocations, showTimeProfiling } from '../../config.js';
3
+ import chalk from 'chalk-extensions';
4
+ import { globby } from 'globby';
5
+ import { out, log, debug } from '../../output.js';
6
+ const {
7
+ timeProfileAsync
8
+ } = await createTimeProfiler(showTimeProfiling);
9
+ import { addBasePath } from './addBasePath.js';
10
+ export async function findTestFiles(config) {
11
+ return await timeProfileAsync('find test files', async () => {
12
+ const testsGlobs = await addBasePath(config.testsBase, config.tests);
13
+ const testsIgnoreGlobs = await addBasePath(config.testsBase, config.testsIgnore);
14
+ await debug('testsGlobs', testsGlobs);
15
+ await debug('testsIgnoreGlobs', testsIgnoreGlobs);
16
+ const globOptions = {
17
+ //cwd: projectDir,
18
+ ignore: testsIgnoreGlobs
19
+ };
20
+ const testFiles = await globby(testsGlobs, testsIgnoreGlobs);
21
+ await debug('testFiles', testFiles);
22
+ return testFiles;
23
+ });
24
+ }
@@ -0,0 +1,22 @@
1
+ import { applyConfigDefaults } from './applyConfigDefaults.js';
2
+ import { findTestFiles } from './findTestFiles.js'; // findTestFiles(config)
3
+
4
+ await mochaDescribe('findTestFiles() function', async function () {
5
+ await mochaIt('finds the tests files', async function () {
6
+ // get the default configs
7
+ const config = await applyConfigDefaults({
8
+ tests: 'unitTesting/**/*.test.js'
9
+ });
10
+ const testFiles = await findTestFiles(config);
11
+ await testFiles.should.include.members(['unitTesting/sampleTests/1.test.js', 'unitTesting/sampleTests/2.test.js']);
12
+ });
13
+ await mochaIt('respects tests base config entry', async function () {
14
+ // get the default configs
15
+ const config = await applyConfigDefaults({
16
+ testsBase: 'src',
17
+ tests: 'unitTesting/**/*.test.js'
18
+ });
19
+ const testFiles = await findTestFiles(config);
20
+ await testFiles.length.should.equal(0);
21
+ });
22
+ });
@@ -0,0 +1,11 @@
1
+ export async function getAllowedFlags(allowedArguments) {
2
+ const allowedFlags = {};
3
+
4
+ for (const option in allowedArguments) {
5
+ if ('flag' in allowedArguments[option]) {
6
+ allowedFlags[allowedArguments[option].flag] = option;
7
+ }
8
+ }
9
+
10
+ return allowedFlags;
11
+ }
@@ -0,0 +1,20 @@
1
+ import { getAllowedFlags } from './getAllowedFlags.js'; // findTestFiles(config)
2
+
3
+ await mochaDescribe('getAllowedFlags() function', async function () {
4
+ await mochaIt('extracts the flags from an allowedArguments object', async function () {
5
+ const allowedArguments = {
6
+ 'config': {
7
+ flag: 'c',
8
+ hasValue: true
9
+ },
10
+ 'watch': {
11
+ flag: 'w',
12
+ hasValue: false
13
+ }
14
+ };
15
+ const allowedFlags = await getAllowedFlags(allowedArguments);
16
+ await allowedFlags.should.have.keys(['c', 'w']);
17
+ await allowedFlags.c.should.equal('config');
18
+ await allowedFlags.w.should.equal('watch');
19
+ });
20
+ });
@@ -0,0 +1 @@
1
+ export const globArgCombine = patterns => Array.isArray(patterns) ? patterns.length > 1 ? '{' + patterns.join(',') + '}' : patterns[0] : patterns;
@@ -0,0 +1,18 @@
1
+ import { globArgCombine } from "./globArgCombine.js";
2
+ await mochaDescribe('globArgCombine() function', async function () {
3
+ await mochaIt('leaves strings alone', async function () {
4
+ const testString = '*.test.js';
5
+ const result = await globArgCombine(testString);
6
+ await result.should.equal(testString);
7
+ });
8
+ await mochaIt('extracts the item from a single item array', async function () {
9
+ const testStringsArray = ['*.test.js'];
10
+ const result = await globArgCombine(testStringsArray);
11
+ await result.should.equal(testStringsArray[0]);
12
+ });
13
+ await mochaIt('combined an array into a multi option glob e.g. {a,b}', async function () {
14
+ const testStringsArray = ['*.test.js', '*.spec.js'];
15
+ const result = await globArgCombine(testStringsArray);
16
+ await result.should.equal(`{${testStringsArray[0]},${testStringsArray[1]}}`);
17
+ });
18
+ });
@@ -0,0 +1,11 @@
1
+ import { out as mainOut, log, debug } from '../../output.js';
2
+ const reservedKeys = ['describe', 'test', 'it', 'before', 'after', 'beforeEach', 'afterEach', 'beforeAll', 'afterAll'];
3
+ export async function injectProperties(basePackage, injectProperties, from, customOut = undefined) {
4
+ const out = customOut ? async (...texts) => await customOut(...texts) : async (...texts) => await mainOut(...texts);
5
+
6
+ for (const key in injectProperties) {
7
+ if (await reservedKeys.includes(key)) {
8
+ await out(`Error: key '${key}' is reserved. Please do not use this key. From '${from}'.`); //process.exit(1)
9
+ }
10
+ }
11
+ }
@@ -0,0 +1,75 @@
1
+ import { injectProperties } from "./injectProperties.js";
2
+ import chalk from 'chalk-extensions';
3
+ await mochaDescribe('injectProperties() function', async function () {
4
+ await mochaIt('complains if a reserved property is given', async function () {
5
+ let outBuffer = '';
6
+
7
+ const customOut = (...texts) => {
8
+ //console.log(chalk.red`outBuffer1`, outBuffer)
9
+ console.log(...texts);
10
+ outBuffer += texts.join(' ') + '\n'; // join and save to the buffer
11
+ //console.log(chalk.red`outBuffer2`, outBuffer)
12
+ };
13
+
14
+ const errorString = 'is reserved';
15
+ const basePacket = {};
16
+ let properties;
17
+ outBuffer = '';
18
+ properties = {
19
+ describe: true
20
+ };
21
+ await injectProperties(basePacket, properties, '', customOut);
22
+ await outBuffer.should.include(errorString);
23
+ outBuffer = '';
24
+ properties = {
25
+ it: true
26
+ };
27
+ await injectProperties(basePacket, properties, '', customOut);
28
+ await outBuffer.should.include(errorString);
29
+ outBuffer = '';
30
+ properties = {
31
+ test: true
32
+ };
33
+ await injectProperties(basePacket, properties, '', customOut);
34
+ await outBuffer.should.include(errorString);
35
+ outBuffer = '';
36
+ properties = {
37
+ before: true
38
+ };
39
+ await injectProperties(basePacket, properties, '', customOut);
40
+ await outBuffer.should.include(errorString);
41
+ outBuffer = '';
42
+ properties = {
43
+ after: true
44
+ };
45
+ await injectProperties(basePacket, properties, '', customOut);
46
+ await outBuffer.should.include(errorString);
47
+ outBuffer = '';
48
+ properties = {
49
+ beforeEach: true
50
+ };
51
+ await injectProperties(basePacket, properties, '', customOut);
52
+ await outBuffer.should.include(errorString);
53
+ outBuffer = '';
54
+ properties = {
55
+ afterEach: true
56
+ };
57
+ await injectProperties(basePacket, properties, '', customOut);
58
+ await outBuffer.should.include(errorString);
59
+ }); // mochaIt('complains if a passed property conflics with a base property', function() {
60
+ // let outBuffer = ''
61
+ // const customOut = sync((...texts) => {
62
+ // console.log(...texts)
63
+ // outBuffer += texts.join(' ') + '\n' // join and save to the buffer
64
+ // })
65
+ // const errorString = 'is reserved'
66
+ // const basePacket = {}
67
+ // let properties
68
+ // outBuffer = ''
69
+ // properties = {
70
+ // describe: true
71
+ // }
72
+ // injectProperties(basePacket, properties, '', customOut)
73
+ // outBuffer.should.include(errorString)
74
+ // })
75
+ });
@@ -0,0 +1,3 @@
1
+ import sxyLoaderConfig from '../../../sxy-loader.config.js';
2
+ import { createLoad } from 'sxy-loader';
3
+ export const load = await createLoad(import.meta.url, sxyLoaderConfig);
@@ -0,0 +1,7 @@
1
+ import { load } from "./load.js";
2
+ await mochaDescribe('load import (sxy loader)', async function () {
3
+ await mochaIt('load is a function with a cache', async function () {
4
+ await load.should.be.a('function');
5
+ await load.should.include.key('cache');
6
+ });
7
+ });
@@ -0,0 +1,21 @@
1
+ import { loadConfig as sxyLoadConfig, loadConfigExact as sxyLoadConfigExact, createTimeProfiler } from 'sxy-dev-tools';
2
+ import { packageName, cliName, configFileName, configLocations, showTimeProfiling } from '../../config.js';
3
+ import chalk from 'chalk-extensions';
4
+ import { out, log, debug } from '../../output.js';
5
+ const {
6
+ timeProfileAsync
7
+ } = await createTimeProfiler(showTimeProfiling);
8
+ export async function loadConfig(customLocation = undefined) {
9
+ return await timeProfileAsync('load config', async () => {
10
+ const configOrNull = customLocation !== undefined ? await sxyLoadConfigExact(customLocation) : await sxyLoadConfig(configFileName, configLocations);
11
+ await debug('configOrNull', typeof configOrNull, configOrNull);
12
+
13
+ if (!configOrNull) {
14
+ await out(await chalk.orange(`[${packageName}] No config found.` + `\nPlease create a ${configFileName}.js/cjs/mjs file in your project root or /config folder.` + `\nOr run \`npx ${cliName} init\` to create one.`));
15
+ await process.exit(0);
16
+ } //log('user config', configOrNull)
17
+
18
+
19
+ return configOrNull;
20
+ });
21
+ }
@@ -0,0 +1,15 @@
1
+ import { loadConfig } from "./loadConfig.js"; // loadConfig(location)
2
+ // location is option
3
+
4
+ await mochaDescribe('loadConfig() function', async function () {
5
+ await mochaIt('loads a user config', async function () {
6
+ const userConfig = await loadConfig();
7
+ userConfig.should.not.be.null;
8
+ });
9
+ await mochaIt('loads a user config from a location passed to it', async function () {
10
+ const configLocation = 'unitTesting/sampleConfig/sxy-test-runner.config.js';
11
+ const userConfig = await loadConfig(configLocation);
12
+ userConfig.should.not.be.null;
13
+ await userConfig.tests.should.equal('alt-config-location');
14
+ });
15
+ });
@@ -0,0 +1,75 @@
1
+ import { createTimeProfiler } from 'sxy-dev-tools';
2
+ import { showTimeProfiling } from '../../config.js';
3
+ import { out, log, debug, error } from '../../output.js';
4
+ import { join } from 'path';
5
+ import chalk from 'chalk-extensions';
6
+ const {
7
+ timeProfileAsync
8
+ } = await createTimeProfiler(showTimeProfiling);
9
+ import { load } from './load.js';
10
+ let loading = null;
11
+ export async function loadTestFile(config, testFile) {
12
+ if (loading !== null) {
13
+ await debug(chalk.yellow`loadTestFile - another file is loading - waiting for it to finish`);
14
+ await loading;
15
+ await debug(chalk.yellow`previous file complete - will now load the file`);
16
+ }
17
+
18
+ const loadPromise = timeProfileAsync(`load test ${testFile}`, async () => {
19
+ const projectDir = await process.cwd(); // eslint-disable-next-line camelcase
20
+
21
+ global.__sxy_test_runner__ = {
22
+ describes: [],
23
+ describeCounter: 1
24
+ };
25
+ const testFileFullUrl = 'file://' + (await join(projectDir, testFile)); //console.log('testFileFullUrl', testFileFullUrl)
26
+
27
+ const test = {
28
+ file: testFile
29
+ };
30
+ const capturingConsoleLog = config.execution.files === 'sequential'; //// capture console.log output
31
+
32
+ let previousConsoleLog;
33
+ const logs = [];
34
+
35
+ if (capturingConsoleLog) {
36
+ previousConsoleLog = console.log; // eslint-disable-line no-console
37
+
38
+ console.log = async (...texts) => await logs.push(texts); // eslint-disable-line no-console
39
+
40
+ } ////
41
+
42
+
43
+ try {
44
+ await load(testFileFullUrl, {// scopeObject: { // experimental idea
45
+ // name: 'scope',
46
+ // contents: {},
47
+ // exposeObject: 'scope'
48
+ // }
49
+ });
50
+ test.describes = global.__sxy_test_runner__.describes;
51
+ test.error = false;
52
+ } catch (e) {
53
+ //error(chalk.red`Error loading file ${testFileFullUrl}`)
54
+ test.error = `Error loading file`;
55
+ } finally {
56
+ test.logs = logs; //// restore previous console.log function
57
+
58
+ if (capturingConsoleLog) {
59
+ if (capturingConsoleLog) {
60
+ console.log = previousConsoleLog; // eslint-disable-line no-console
61
+ }
62
+ } ////
63
+
64
+ } // console.log()
65
+ // console.log('test', test)
66
+ // console.log('describes', test.describes)
67
+ // console.log('its', test.describes[0].its)
68
+ // console.log()
69
+
70
+
71
+ return test;
72
+ });
73
+ loading = loadPromise;
74
+ return await loadPromise;
75
+ }
@@ -0,0 +1,45 @@
1
+ import { loadTestFile } from "./loadTestFile.js";
2
+ import { defaultConfig } from './defaultConfig.js'; // loadTestFile(config, testFile) ???
3
+
4
+ await mochaDescribe('loadTestFile() function', async function () {
5
+ /*
6
+ mochaIt('should load a test file, retreiving describes', function() {
7
+
8
+ const config = defaultConfig
9
+
10
+ const sampleTestFile = 'unitTesting/sampleTests/1.test.js'
11
+
12
+ const test = loadTestFile(config, sampleTestFile)
13
+
14
+ test.describes.length.should.equal(1)
15
+ test.describes.at(-1).counter.should.equal(1)
16
+ test.describes[0].tests.should.be.a('function')
17
+ //test.describes.at(-1).its.at(-1).counter.should.equal(1)
18
+
19
+ })
20
+
21
+ mochaIt('should correctly load a second test file', function() {
22
+
23
+ const config = defaultConfig
24
+
25
+ const sampleTestFile = 'unitTesting/sampleTests/2.test.js'
26
+
27
+ const test = loadTestFile(config, sampleTestFile)
28
+
29
+ test.describes.length.should.equal(1)
30
+ test.describes.at(-1).counter.should.equal(1)
31
+ test.describes[0].tests.should.be.a('function')
32
+ //test.describes.at(-1).its.at(-1).counter.should.equal(2)
33
+
34
+ })
35
+ */
36
+ await mochaIt('should correctly load a file with describes without any its/tests', async function () {
37
+ const config = defaultConfig;
38
+ const sampleTestFile = 'unitTesting/sampleTests/describesWithoutTests.test.js';
39
+ const test = await loadTestFile(config, sampleTestFile); //console.log('ut test', test)
40
+
41
+ await test.describes.length.should.equal(2);
42
+ await (await test.describes.at(-1)).counter.should.equal(2);
43
+ await test.describes[0].tests.should.be.a('function'); //test.describes.at(-1).its.at(-1).counter.should.equal(2)
44
+ });
45
+ });
@@ -0,0 +1,40 @@
1
+ /*
2
+
3
+ I can't remember what this was for.
4
+
5
+ Would need updating to the new file load system if used
6
+
7
+ import { createTimeProfiler } from 'sxy-dev-tools'
8
+ import { packageName, cliName, configFileName, configLocations, showTimeProfiling } from '../../config.js'
9
+ import { join } from 'path'
10
+ const { timeProfileAsync } = createTimeProfiler(showTimeProfiling)
11
+
12
+ // could be used within runTests
13
+ // think its not used now
14
+
15
+ export function loadTestFileStatic(config, testFile) {
16
+
17
+ return timeProfileAsync(`load test ${testFile} statically (standard import)`, () => {
18
+
19
+ //console.log('loadTestFileStatic', config, testFile)
20
+
21
+ const projectDir = process.cwd()
22
+
23
+ global.testState = {
24
+ describes: [],
25
+ describeCounter: 1
26
+ }
27
+
28
+ import( 'file://' + join(projectDir, testFile) )
29
+
30
+ const test = {
31
+ file: testFile,
32
+ describes: global.testState.describes
33
+ }
34
+
35
+ return test
36
+
37
+ } )
38
+
39
+ }
40
+ */
@@ -0,0 +1,29 @@
1
+ /*
2
+ import { loadTestFileStatic } from "./loadTestFileStatic.js"
3
+ import { applyConfigDefaults } from './applyConfigDefaults.js'
4
+
5
+ // loadTestFile(config, testFile) ???
6
+
7
+ mochaDescribe('loadTestFileStatic() function', function() {
8
+
9
+ mochaIt('should load a test file, retreiving describes', function() {
10
+
11
+ const config = applyConfigDefaults({})
12
+
13
+ const sampleTestFile = 'unitTesting/sampleTests/1.test.js'
14
+
15
+ const test = loadTestFileStatic(config, sampleTestFile)
16
+
17
+ test.describes.length.should.equal(1)
18
+ test.describes[0].counter.should.equal(1)
19
+ test.describes[0].its[0].counter.should.equal(1)
20
+
21
+ })
22
+
23
+ // mochaIt('should be able to load a test file again, after cache is cleard', function() {
24
+
25
+
26
+ // })
27
+
28
+ })
29
+ */
@@ -0,0 +1,57 @@
1
+ // watch:
2
+ // once:
3
+ // // --config configLocation
4
+ import { createTimeProfiler } from 'sxy-dev-tools';
5
+ import { packageName, cliName, configFileName, configLocations, showTimeProfiling } from '../../config.js';
6
+ import { join } from 'path';
7
+ import { out, log, debug } from '../../output.js';
8
+ const {
9
+ timeProfileAsync
10
+ } = await createTimeProfiler(showTimeProfiling);
11
+ import { getAllowedFlags } from './getAllowedFlags.js';
12
+ export async function parseCommandLineArguments(allowedArguments) {
13
+ const allowedFlags = await getAllowedFlags(allowedArguments);
14
+ const returnArgs = {};
15
+
16
+ for (let position = 0; position < commandLineArguments.length; position++) {
17
+ const arg = commandLineArguments[position];
18
+
19
+ if ((await arg.slice(0, 2)) === '--') {
20
+ const longFlag = await arg.slice(2);
21
+
22
+ if (longFlag in allowedArguments) {
23
+ if (allowedArguments[longFlag].hasValue) {
24
+ const value = commandLineArguments[++position]; // increment position
25
+
26
+ returnArgs[longFlag] = value;
27
+ } else {
28
+ returnArgs[longFlag] = true;
29
+ }
30
+ } else {
31
+ await log(`[${packageName}] Unknown option ${longFlag}`);
32
+ }
33
+ } else if ((await arg.slice(0, 1)) === '-') {
34
+ const shortFlag = await arg.slice(1);
35
+
36
+ if (shortFlag in allowedFlags) {
37
+ const longFlag = allowedFlags[shortFlag];
38
+
39
+ if (longFlag in returnArgs) {
40
+ await log(`[${packageName}] Option ${longFlag} already set, being overwritten by ${shortFlag}`);
41
+ }
42
+
43
+ if (allowedArguments[longFlag].hasValue) {
44
+ const value = commandLineArguments[++position]; // increment position
45
+
46
+ returnArgs[longFlag] = value;
47
+ } else {
48
+ returnArgs[longFlag] = true;
49
+ }
50
+ } else {
51
+ await log(`[${packageName}] Unknown flag ${shortFlag}`);
52
+ }
53
+ }
54
+ }
55
+
56
+ return returnArgs;
57
+ }
@@ -0,0 +1,21 @@
1
+ import { parseCommandLineArguments } from './parseCommandLineArguments.js'; // parseCommandLineArguments(allowedArguments)
2
+
3
+ await mochaDescribe('getAllowedFlags() function', async function () {
4
+ await mochaIt('extracts the flags from an allowedArguments object', async function () {
5
+ const allowedArguments = {
6
+ 'config': {
7
+ flag: 'c',
8
+ hasValue: true
9
+ },
10
+ 'watch': {
11
+ flag: 'w',
12
+ hasValue: false
13
+ }
14
+ };
15
+ global.commandLineArguments = ['--config', 'foo bar'];
16
+ const parsedArgs = await parseCommandLineArguments(allowedArguments); //console.log('parsed Args', parsedArgs)
17
+
18
+ await parsedArgs.should.have.key('config');
19
+ await parsedArgs.config.should.equal('foo bar');
20
+ });
21
+ });
@@ -0,0 +1,88 @@
1
+ import { timeProfileAsync } from './timeProfier.js';
2
+ import { runTasks } from './runTasks.js';
3
+ import { addExports } from './addExports.js';
4
+ import { debug } from '../../output.js';
5
+ import { runIt } from './runIt.js';
6
+ export async function parseDescribe(config, describe) {
7
+ return await timeProfileAsync(`parse its from describe ${describe.thing}`, async () => {
8
+ let itCounter = 1;
9
+ const its = []; // create functions to pass back
10
+ // afterDescribe
11
+
12
+ let afterDescribeFunc;
13
+
14
+ async function afterDescribe(func) {
15
+ if (typeof func !== 'function') {
16
+ throw new Error(`afterDescribe() error, argument passed to afterDescribe() must be a function,` + ` received ${typeof func}`);
17
+ }
18
+
19
+ afterDescribeFunc = func;
20
+ } // beforeEachTest
21
+
22
+
23
+ let beforeEachTestFunc;
24
+
25
+ async function beforeEachTest(func) {
26
+ if (typeof func !== 'function') {
27
+ throw new Error(`afterDescribe() error, argument passed to afterDescribe() must be a function,` + ` received ${typeof func}`);
28
+ }
29
+
30
+ beforeEachTestFunc = func;
31
+ } // afterEachTest
32
+
33
+
34
+ let afterEachTestFunc;
35
+
36
+ async function afterEachTest(func) {
37
+ if (typeof func !== 'function') {
38
+ throw new Error(`afterDescribe() error, argument passed to afterDescribe() must be a function,` + ` received ${typeof func}`);
39
+ }
40
+
41
+ afterEachTestFunc = func;
42
+ } // it
43
+
44
+
45
+ async function it(should, test) {
46
+ const thisItCounter = itCounter++;
47
+ await its.push({
48
+ counter: thisItCounter,
49
+ should,
50
+ test //beforeEachTestExports
51
+
52
+ });
53
+ }
54
+
55
+ const test = it;
56
+ const beforeDescribeExports = {};
57
+ await configBeforeEachDescribe(config, beforeDescribeExports);
58
+ const describeParcel = {
59
+ it,
60
+ test,
61
+ afterDescribe,
62
+ beforeEachTest,
63
+ afterEachTest
64
+ };
65
+ await addExports(describeParcel, beforeDescribeExports);
66
+ await describe.tests(describeParcel);
67
+ return {
68
+ its,
69
+ beforeDescribeExports,
70
+ afterDescribeFunc,
71
+ beforeEachTestFunc,
72
+ afterEachTestFunc
73
+ };
74
+ });
75
+ }
76
+
77
+ async function configBeforeEachDescribe(config, exports) {
78
+ if (config.beforeEachDescribe) {
79
+ const theExports = await runTasks(config.beforeEachDescribe, undefined);
80
+ await addExports(exports, theExports);
81
+ }
82
+ }
83
+
84
+ async function configAfterEachDescribe(config, exports) {
85
+ if (config.afterEachDescribe) {
86
+ await runTasks(config.afterEachDescribe, exports);
87
+ }
88
+ }
@@ -0,0 +1,17 @@
1
+ import { applyConfigDefaults } from './applyConfigDefaults.js';
2
+ import { loadTestFile } from './loadTestFile.js';
3
+ import { parseDescribe } from './parseDescribe.js';
4
+ const defaultConfig = await applyConfigDefaults({}); // const beforeAfterTestFile = 'unitTesting/runTest/beforeAfter.test.js'
5
+ // const beforeAfterTest = loadTestFile(defaultConfig, beforeAfterTestFile)
6
+
7
+ await mochaDescribe('runDescribe() function', async function () {
8
+ await mochaIt('should run an it block that was loaded from a test file', async function () {
9
+ const sampleTestFile = 'unitTesting/runTest/1.test.js';
10
+ const sampleTest = await loadTestFile(defaultConfig, sampleTestFile);
11
+ const sampleDescribe = sampleTest.describes[0];
12
+ const parsedDescribe = await parseDescribe(defaultConfig, sampleDescribe);
13
+ await parsedDescribe.should.include.keys(['its', 'beforeDescribeExports', 'afterDescribeFunc', 'beforeEachTestFunc', 'afterEachTestFunc']); //console.log('parsedDescribe', parsedDescribe)
14
+
15
+ await parsedDescribe.its[0]['should'].should.equal('1 should equal 1');
16
+ });
17
+ });