sxy-test-runner 1.0.3 → 1.0.6

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.
@@ -1,24 +1,38 @@
1
- import { defaultConfig } from './defaultConfig.js';
2
- import { applyConfigDefaults } from './applyConfigDefaults.js';
3
- import { loadTestFile } from './loadTestFile.js'; // loadTestFile(config, testFile) ???
1
+ import { loadTestFile } from "./loadTestFile.js";
2
+ import { defaultConfig } from './defaultConfig.js'; // loadTestFile(config, testFile) ???
4
3
 
5
4
  await mochaDescribe('loadTestFile() function', async function () {
6
- await mochaIt('should load a test file, retreiving describes', async function () {
7
- const config = defaultConfig;
8
- const sampleTestFile = 'unitTesting/sampleTests/1.test.js';
9
- const test = await loadTestFile(config, sampleTestFile);
10
- await test.describes.length.should.equal(1);
11
- await (await test.describes.at(-1)).counter.should.equal(1);
12
- await test.describes[0].tests.should.be.a('function'); //test.describes.at(-1).its.at(-1).counter.should.equal(1)
13
- });
14
- await mochaIt('should correctly load a second test file', async function () {
15
- const config = defaultConfig;
16
- const sampleTestFile = 'unitTesting/sampleTests/2.test.js';
17
- const test = await loadTestFile(config, sampleTestFile);
18
- await test.describes.length.should.equal(1);
19
- await (await test.describes.at(-1)).counter.should.equal(1);
20
- await test.describes[0].tests.should.be.a('function'); //test.describes.at(-1).its.at(-1).counter.should.equal(2)
21
- });
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
+ */
22
36
  await mochaIt('should correctly load a file with describes without any its/tests', async function () {
23
37
  const config = defaultConfig;
24
38
  const sampleTestFile = 'unitTesting/sampleTests/describesWithoutTests.test.js';
@@ -28,24 +42,4 @@ await mochaDescribe('loadTestFile() function', async function () {
28
42
  await (await test.describes.at(-1)).counter.should.equal(2);
29
43
  await test.describes[0].tests.should.be.a('function'); //test.describes.at(-1).its.at(-1).counter.should.equal(2)
30
44
  });
31
- await mochaIt('should capture console.log output from a test file, when files are running sequentially', async function () {
32
- const config = await applyConfigDefaults({
33
- execution: {
34
- files: 'sequential'
35
- }
36
- });
37
- const sampleTestFile = 'unitTesting/sampleTests/consoleLog.test.js';
38
- const testBlock = await loadTestFile(config, sampleTestFile);
39
- await testBlock.consoleLogs.should.deep.equal([['foo'], ['bar']]);
40
- });
41
- await mochaIt('should capture console.log output from a test file, when files are running sequentially', async function () {
42
- const config = await applyConfigDefaults({
43
- execution: {
44
- files: 'parallel'
45
- }
46
- });
47
- const sampleTestFile = 'unitTesting/sampleTests/consoleLog.test.js';
48
- const testBlock = await loadTestFile(config, sampleTestFile);
49
- await chaiShould.not.exist(testBlock.consoleLogs);
50
- }); // should not log output when running in parallel
51
45
  });
@@ -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
+ });
@@ -1,141 +1,29 @@
1
- // to be populated with the func from runTestFile.js
2
- import { createTimeProfiler } from 'sxy-dev-tools';
3
- import { showTimeProfiling } from '../../config.js';
4
- import { out, log, debug } from '../../output.js';
5
- import { shouldCaptureConsoleLog } from './shouldCaptureConsoleLog.js';
6
- import { overrideConsoleLog } from './overrideConsoleLog.js';
7
- import { addExports } from './addExports.js';
8
- import { configBeforeEachDescribe, configAfterEachDescribe } from './configBeforeAfterFuncs.js';
9
- import { runIt } from './runIt.js';
10
- const {
11
- timeProfileAsync
12
- } = await createTimeProfiler(showTimeProfiling);
1
+ import { timeProfileAsync } from './timeProfier.js';
2
+ import { parseDescribe } from './parseDescribe.js';
3
+ import { runDescribeRun } from './runDescribeRun.js';
13
4
  export async function runDescribe(config, describe) {
14
5
  return await timeProfileAsync(`run describe ${describe.thing}`, async () => {
15
- // afterDescribe
16
- let afterDescribeFunc;
6
+ const capturingConsoleLog = config.execution.describes === 'sequential'; //// capture console.log output
17
7
 
18
- async function afterDescribe(func) {
19
- if (typeof func !== 'function') {
20
- throw new Error(`afterDescribe() error, argument passed to afterDescribe() must be a function,` + ` received ${typeof func}`);
21
- }
8
+ let previousConsoleLog;
9
+ const logs = [];
22
10
 
23
- afterDescribeFunc = func;
24
- } // beforeEachTest
11
+ if (capturingConsoleLog) {
12
+ previousConsoleLog = console.log; // eslint-disable-line no-console
25
13
 
14
+ console.log = async (...texts) => await logs.push(texts); // eslint-disable-line no-console
26
15
 
27
- let beforeEachTestFunc;
16
+ } ////
28
17
 
29
- async function beforeEachTest(func) {
30
- if (typeof func !== 'function') {
31
- throw new Error(`afterDescribe() error, argument passed to afterDescribe() must be a function,` + ` received ${typeof func}`);
32
- }
33
18
 
34
- beforeEachTestFunc = func;
35
- } // afterEachTest
19
+ const parsedDescribe = await parseDescribe(config, describe);
20
+ const describeResult = await runDescribeRun(config, describe, parsedDescribe);
21
+ describeResult.logs = logs;
36
22
 
37
-
38
- let afterEachTestFunc;
39
-
40
- async function afterEachTest(func) {
41
- if (typeof func !== 'function') {
42
- throw new Error(`afterDescribe() error, argument passed to afterDescribe() must be a function,` + ` received ${typeof func}`);
43
- }
44
-
45
- afterEachTestFunc = func;
46
- }
47
-
48
- let itCounter = 1;
49
- const its = []; // create functions to pass back
50
- // it
51
-
52
- async function it(should, test) {
53
- const thisItCounter = itCounter++;
54
- await its.push({
55
- counter: thisItCounter,
56
- should,
57
- test
58
- });
59
- }
60
-
61
- const test = it;
62
- const describeExports = {};
63
- await configBeforeEachDescribe(config, describeExports);
64
- const describeParcel = {
65
- it,
66
- test,
67
- afterDescribe,
68
- beforeEachTest,
69
- afterEachTest
70
- };
71
- await addExports(describeParcel, describeExports); // capture the console.log output if we can
72
-
73
- let originalConsoleLog, replacementConsoleLog;
74
-
75
- if (await shouldCaptureConsoleLog(config, 'describe')) {
76
- ({
77
- originalConsoleLog,
78
- replacementConsoleLog
79
- } = await overrideConsoleLog());
80
- }
81
-
82
- try {
83
- await describe.tests(describeParcel);
84
- } catch (e) {
85
- const describeErrorResult = {
86
- counter: describe.counter,
87
- thing: describe.thing,
88
- error: e.message,
89
- success: false
90
- };
91
-
92
- if (await shouldCaptureConsoleLog(config, 'describe')) {
93
- console.log = originalConsoleLog; // eslint-disable-line no-console
94
-
95
- describeErrorResult.consoleLogs = replacementConsoleLog.logs;
96
- }
97
-
98
- return describeErrorResult;
99
- } //!!!!! should this be here, or at the end after its?
100
-
101
-
102
- let describeConsoleLogs;
103
-
104
- if (await shouldCaptureConsoleLog(config, 'describe')) {
105
- console.log = originalConsoleLog; // eslint-disable-line no-console
106
-
107
- describeConsoleLogs = replacementConsoleLog.logs; //!!!!!! This needs to be applied
23
+ if (capturingConsoleLog) {
24
+ console.log = previousConsoleLog; // eslint-disable-line no-console
108
25
  }
109
26
 
110
- const itResults = [];
111
-
112
- for (const it of its) {
113
- await itResults.push(await runIt(config, it, beforeEachTestFunc, afterEachTestFunc));
114
- }
115
-
116
- const itResultsSummary = {
117
- total: 0,
118
- passes: 0
119
- };
120
-
121
- for (const itResult of itResults) {
122
- itResultsSummary.total += +(itResult.success !== null);
123
- itResultsSummary.passes += +itResult.success;
124
- }
125
-
126
- await debug('itResultsSummary', itResultsSummary);
127
- const describeResult = {
128
- counter: describe.counter,
129
- thing: describe.thing,
130
- error: false,
131
- success: itResultsSummary.total > 0 ? itResultsSummary.passes === itResultsSummary.total : null,
132
- itResults,
133
- itResultsSummary,
134
- consoleLogs: describeConsoleLogs
135
- }; // run after
136
-
137
- if (typeof afterDescribeFunc === 'function') await afterDescribeFunc();
138
- await configAfterEachDescribe(config, describeExports);
139
27
  return describeResult;
140
28
  });
141
29
  }
@@ -0,0 +1,115 @@
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 runDescribeOld(config, describe) {
7
+ return await timeProfileAsync(`run 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 describeExports = {};
57
+ await configBeforeEachDescribe(config, describeExports);
58
+ const describeParcel = {
59
+ it,
60
+ test,
61
+ afterDescribe,
62
+ beforeEachTest,
63
+ afterEachTest
64
+ };
65
+ await addExports(describeParcel, describeExports);
66
+ await describe.tests(describeParcel); //console.log('its', its)
67
+ // const beforeEachDescribeExports = (config.beforeEachDescribe)
68
+ // ? runTasks(config, config.beforeEachDescribe)
69
+ // : {}
70
+ //const thisDescribeCounter = describeCounter++ // assign THEN increment
71
+ //let itCounter = 1
72
+
73
+ const itResults = [];
74
+
75
+ for (const it of its) {
76
+ await itResults.push(await runIt(config, it, beforeEachTestFunc, afterEachTestFunc));
77
+ }
78
+
79
+ const itResultsSummary = {
80
+ total: 0,
81
+ passes: 0
82
+ };
83
+
84
+ for (const itResult of itResults) {
85
+ itResultsSummary.total += +(itResult.success !== null);
86
+ itResultsSummary.passes += +itResult.success;
87
+ }
88
+
89
+ await debug('itResultsSummary', itResultsSummary);
90
+ const describeResult = {
91
+ counter: describe.counter,
92
+ thing: describe.thing,
93
+ success: itResultsSummary.total > 0 ? itResultsSummary.passes === itResultsSummary.total : null,
94
+ itResults,
95
+ itResultsSummary
96
+ }; // run after
97
+
98
+ if (typeof afterDescribeFunc === 'function') await afterDescribeFunc();
99
+ await configAfterEachDescribe(config, describeExports);
100
+ return describeResult;
101
+ });
102
+ }
103
+
104
+ async function configBeforeEachDescribe(config, exports) {
105
+ if (config.beforeEachDescribe) {
106
+ const theExports = await runTasks(config.beforeEachDescribe, undefined);
107
+ await addExports(exports, theExports);
108
+ }
109
+ }
110
+
111
+ async function configAfterEachDescribe(config, exports) {
112
+ if (config.afterEachDescribe) {
113
+ await runTasks(config.afterEachDescribe, exports);
114
+ }
115
+ }