-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
/
smoke.runner.js
932 lines (856 loc) · 31 KB
/
smoke.runner.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
import fs from 'node:fs/promises'
import url from 'node:url'
import path from 'node:path'
import assert from 'node:assert'
import { expect } from 'expect-webdriverio'
import { sleep } from '../packages/wdio-utils/build/utils.js'
import { SevereServiceError } from '../packages/node_modules/webdriverio/build/index.js'
const __dirname = path.dirname(url.fileURLToPath(import.meta.url))
const baseConfig = path.resolve(__dirname, 'helpers', 'config.js')
const parallelMultiRemoteBaseConfig = path.resolve(__dirname, 'helpers', 'parallel-multiremote-config.js')
const jasmineConfig = path.resolve(__dirname, 'helpers', 'configJasmine.js')
const allPassedConfig = path.resolve(__dirname, 'tests-cli-spec-arg/wdio-with-all-passed.conf.js')
const noArgConfig = path.resolve(__dirname, 'tests-cli-spec-arg/wdio-with-no-arg.conf.js')
const severalPassedConfig = path.resolve(__dirname, 'tests-cli-spec-arg/wdio-with-failed.conf.js')
import launch from './helpers/launch.js'
import {
SERVICE_LOGS,
LAUNCHER_LOGS,
REPORTER_LOGS,
JASMINE_REPORTER_LOGS,
CUCUMBER_REPORTER_LOGS,
} from './helpers/fixtures.js'
async function fileExists (path) {
try {
await fs.access(path)
return true
} catch {
return false
}
}
async function runTests (tests) {
/**
* Usage example: `npm run test:smoke -- customService`
*/
const testFilter = process.argv[2]
if (process.env.CI || testFilter) {
const testsFiltered = testFilter ? tests.filter(test => test.name === testFilter) : tests
if (testsFiltered.length === 0) {
throw new Error(
`No test was selected! Smoke test "${testFilter}" ` +
`picked but only ${tests.map(test => test.name).join(', ')} available`
)
}
// sequential
for (const test of testsFiltered) {
await test()
}
} else {
// parallel
await Promise.all(tests.map(test => test().catch((err) => {
throw new Error(`Smoke test failed with name ${test.name}, ${err.stack}`)
})))
}
}
/**
* Mocha wdio testrunner tests
*/
const mochaTestrunner = async () => {
const { skippedSpecs } = await launch('mochaTestrunner', baseConfig, {
specs: [
'../mocha/test.ts',
path.resolve(__dirname, 'mocha', 'test-middleware.ts'),
path.resolve(__dirname, 'mocha', 'test-waitForElement.ts'),
path.resolve(__dirname, 'mocha', 'test-skipped.ts'),
path.resolve(__dirname, 'mocha', 'cjs', 'test-cjs.js')
]
})
/**
* assertion fails in Windows
* ToDo(Christian): fix
*/
if (process.platform === 'win32') {
return
}
assert.strictEqual(skippedSpecs, 1)
}
/**
* Mocha wdio testrunner tests with asynchronous execution, also checks
* if `spec` CLI arguments are relative to cwd
*/
const mochaAsyncTestrunner = async () => {
const { skippedSpecs } = await launch(
'mochaAsyncTestrunner',
path.resolve(__dirname, 'helpers', 'command.hook.config.js'),
{
spec: ['./tests/mocha/test-async.ts']
}
)
assert.strictEqual(skippedSpecs, 0)
}
/**
* Test if you can run CJS tests
*/
const cjsTestrunner = async () => {
const { skippedSpecs } = await launch('cjsTestrunner', baseConfig, {
specs: [path.resolve(__dirname, 'mocha', 'cjs', 'test-cjs.js')]
})
assert.strictEqual(skippedSpecs, 0)
}
/**
* Jasmine wdio testrunner tests
*/
const jasmineTestrunner = async () => {
const logFile = path.resolve(__dirname, 'helpers', 'expectationResults.log')
await fs.rm(logFile, { force: true })
const { skippedSpecs } = await launch('jasmineTestrunner', jasmineConfig, {
specs: [
path.resolve(__dirname, 'jasmine', 'test.js'),
path.resolve(__dirname, 'jasmine', 'test-skipped.js')
],
framework: 'jasmine'
})
/**
* assertion fails in Windows
* ToDo(Christian): fix
*/
if (process.platform === 'win32') {
return
}
assert.strictEqual(skippedSpecs, 1)
assert.equal(
(await fs.readFile(logFile, 'utf-8')).toString(),
[
'expect(number).toBe(number)',
'expect(number).toBe(number)',
'expect(number).toBe(number)',
'expect(object).toEqual(object)',
'expect(object).toBeFalse(boolean)',
'expect(object).toHaveTitle(object)',
'expect(object).toHaveTitle(object)',
'expect(object).toHaveUrl(object)',
'expect(object).toHaveUrl(object)',
'expect(string).toHaveTitle(object)',
'expect(object).toBeDisplayed(object)',
'expect(object).toBeDisplayed(object)',
'expect(number).toBe(number)',
'expect(number).toBe(number)',
'expect(object).toBeDefined(function)',
'expect(function).toBeInstanceOf(function)',
'expect(object).testMatcher(number)',
''
].join('\n')
)
}
/**
* Jasmine reporter
*/
const jasmineReporter = async () => {
await launch('jasmineReporter', baseConfig, {
specs: [path.resolve(__dirname, 'jasmine', 'reporter.js')],
reporters: [['smoke-test', { foo: 'bar' }]],
framework: 'jasmine',
outputDir: __dirname + '/jasmine'
}).catch((err) => err) // error expected
await sleep(100)
const reporterLogsPath = path.join(__dirname, 'jasmine', 'wdio-0-0-smoke-test-reporter.log')
const reporterLogs = await fs.readFile(reporterLogsPath)
expect(reporterLogs.toString()).toEqual(JASMINE_REPORTER_LOGS)
await fs.unlink(reporterLogsPath)
}
/**
* Jasmine timeout test
*/
const jasmineTimeout = async () => {
const logFile = path.join(__dirname, 'jasmineTimeout.spec.log')
await launch('jasmineTimeout', baseConfig, {
specs: [path.resolve(__dirname, 'jasmine', 'test-timeout.js')],
reporters: [
['spec', {
outputDir: __dirname,
stdout: false,
logFile
}]
],
framework: 'jasmine'
}).catch((err) => err) // error expected
// eslint-disable-next-line no-control-regex
const specLogs = (await fs.readFile(logFile)).toString().replace(/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g, '')
assert.ok(
specLogs.includes('Error: Timeout - Async function did not complete within 1000ms (custom timeout)'),
'spec was not failing due to timeout error'
)
assert.ok(
specLogs.includes('at listOnTimeout (node:internal'),
'spec was not failing a sync assertion error'
)
assert.ok(
!specLogs.includes('RangeError: Maximum call stack size exceeded'),
'spec was failing due to unexpected "Maximum call stack size exceeded"'
)
assert.ok(
specLogs.includes('✓ should allow also async assertions afterwards'),
'spec should also allow async assertions afterwards'
)
}
/**
* Jasmine afterAll is wrongly reported as a failing test - issue #8979
* https://github.com/webdriverio/webdriverio/issues/8979
*/
const jasmineAfterAll = async () => {
const logFile = path.join(__dirname, 'jasmineAfterAll.spec.log')
await launch('jasmineAfterAll', baseConfig, {
specs: [path.resolve(__dirname, 'jasmine', 'afterAll-report.js')],
reporters: [
['spec', {
outputDir: __dirname,
stdout: false,
logFile
}]
],
framework: 'jasmine'
}).catch((err) => err) // error expected
// eslint-disable-next-line no-control-regex
const specLogs = (await fs.readFile(logFile)).toString().replace(/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g, '')
assert.ok(
specLogs.includes('Testing after all hook'),
'spec did not execute the expected describe'
)
assert.ok(
specLogs.includes('actual expected') && specLogs.includes('truefalse'),
'spec did not fail with the expected check'
)
assert.ok(
specLogs.includes('✖ Should fail'),
'spec did not fail on the expected test'
)
assert.ok(
!specLogs.includes('✖ "after all" hook'),
'spec reported the after all hook as a failed test'
)
}
/**
* Jasmine verify failSpecWithNoExpectations support
*/
const jasmineFailSpecWithNoExpectations = async () => {
const logFile = path.join(__dirname, 'jasmineWithNoExpectations.spec.log')
await launch('jasmineAfterAll', baseConfig, {
specs: [path.resolve(__dirname, 'jasmine', 'jasmineWithNoExpectations.js')],
reporters: [
['spec', {
outputDir: __dirname,
stdout: false,
logFile
}]
],
framework: 'jasmine',
jasmineOpts: {
failSpecWithNoExpectations: true
}
}).catch((err) => err) // error expected
// eslint-disable-next-line no-control-regex
const specLogs = (await fs.readFile(logFile)).toString().replace(/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g, '')
assert.ok(
specLogs.includes('No assertions found in test'),
'spec did not fail with the expected check'
)
}
/**
* Cucumber wdio testrunner tests
*/
const cucumberTestrunner = async () => {
const { skippedSpecs } = await launch(
'cucumberTestrunner',
path.resolve(__dirname, 'helpers', 'cucumber-hooks.conf.js'),
{
specs: [
path.resolve(__dirname, 'cucumber', 'test.feature'),
path.resolve(__dirname, 'cucumber', 'test-skipped.feature')
],
cucumberOpts: {
tags: '(not @SKIPPED_TAG)',
ignoreUndefinedDefinitions: true,
retry: 1,
retryTagFilter: '@retry',
scenarioLevelReporter: true
}
}
)
assert.strictEqual(skippedSpecs, 1)
}
/**
* Cucumber wdio testrunner -- run single scenario by line number
*/
const cucumberTestrunnerByLineNumber = async () => {
const logFile = path.join(__dirname, 'cucumber', 'cucumberTestrunnerByLineNumber.log')
await fs.rm(logFile, { force: true })
await launch(
'cucumberTestrunnerByLineNumber',
path.resolve(__dirname, 'helpers', 'cucumber-hooks.conf.js'),
{
spec: [path.resolve(__dirname, 'cucumber', 'test.feature:10')],
cucumberOpts: {
tags: '(not @SKIPPED_TAG)',
scenarioLevelReporter: false
},
reporters: [
['spec', {
outputDir: __dirname,
stdout: false,
logFile
}]]
}
)
// eslint-disable-next-line no-control-regex
const specLogs = (await fs.readFile(logFile)).toString().replace(/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g, '')
assert.ok(
specLogs.includes('Sync Execution'),
'scenario not executed in feature by line number'
)
assert.ok(
!specLogs.includes('Retry Check'),
'extra scenarios not filtered out by line number'
)
}
/**
* Cucumber fail due to failAmbiguousDefinitions
*/
const cucumberFailAmbiguousDefinitions = async () => {
const hasFailed = await launch(
'cucumberFailAmbiguousDefinitions',
path.resolve(__dirname, 'helpers', 'cucumber-hooks.conf.js'),
{
specs: [path.resolve(__dirname, 'cucumber', 'test.feature')],
cucumberOpts: {
ignoreUndefinedDefinitions: true,
failAmbiguousDefinitions: true,
name: ['failAmbiguousDefinitions']
}
}
).then(
() => false,
() => true
)
assert.equal(hasFailed, true)
}
/**
* Cucumber reporter
*/
const cucumberReporter = async () => {
const basePath = path.resolve(__dirname, 'cucumber', 'reporter')
await launch(
'cucumberReporter',
path.resolve(basePath, 'reporter.config.js'),
{
specs: [path.resolve(basePath, 'reporter.feature')],
outputDir: basePath,
}
).catch((err) => err) // error expected
await sleep(100)
const reporterLogsPath = path.join(basePath, 'wdio-0-0-smoke-test-reporter.log')
const reporterLogs = await fs.readFile(reporterLogsPath)
assert.equal(reporterLogs.toString(), CUCUMBER_REPORTER_LOGS)
await fs.unlink(reporterLogsPath)
}
/**
* wdio test run with custom service
*/
const customService = async () => {
await launch('customService', baseConfig, {
specs: [path.resolve(__dirname, 'mocha', 'service.js')],
services: [['smoke-test', { foo: 'bar' }]]
})
await sleep(100)
const serviceLogs = await fs.readFile(path.join(__dirname, 'helpers', 'service.log'))
assert.equal(serviceLogs.toString(), SERVICE_LOGS)
const launcherLogs = await fs.readFile(path.join(__dirname, 'helpers', 'launcher.log'))
assert.equal(launcherLogs.toString(), LAUNCHER_LOGS)
}
/**
* wdio test run with custom service
*/
const customCJSService = async () => {
await launch('customCJSService', baseConfig, {
specs: [path.resolve(__dirname, 'mocha', 'service.js')],
services: [['smoke-test-cjs', { foo: 'bar' }]]
})
await sleep(100)
const serviceLogs = await fs.readFile(path.join(__dirname, 'helpers', 'service.log'))
assert.equal(serviceLogs.toString(), SERVICE_LOGS)
const launcherLogs = await fs.readFile(path.join(__dirname, 'helpers', 'launcher.log'))
assert.equal(launcherLogs.toString(), LAUNCHER_LOGS)
}
/**
* wdio test run with custom reporter as string
*/
const customReporterString = async () => {
await launch('customReporterString', baseConfig, {
specs: [path.resolve(__dirname, 'mocha', 'reporter.js')],
reporters: [['smoke-test', { foo: 'bar' }]]
})
await sleep(100)
const reporterLogsPath = path.join(__dirname, 'helpers', 'wdio-0-0-smoke-test-reporter.log')
const reporterLogs = await fs.readFile(reporterLogsPath)
assert.equal(reporterLogs.toString(), REPORTER_LOGS)
await fs.unlink(reporterLogsPath)
}
/**
* wdio test run with custom reporter as object
*/
const customReporterObject = async () => {
await launch(
'customReporterObject',
path.resolve(__dirname, 'helpers', 'reporter.conf.js'),
)
await sleep(100)
const reporterLogsWithReporterAsObjectPath = path.join(__dirname, 'helpers', 'wdio-0-0-CustomSmokeTestReporter-reporter.log')
const reporterLogsWithReporterAsObject = await fs.readFile(reporterLogsWithReporterAsObjectPath)
assert.equal(reporterLogsWithReporterAsObject.toString(), REPORTER_LOGS)
await fs.unlink(reporterLogsWithReporterAsObjectPath)
}
/**
* wdio test run with before/after Test/Hook
*/
const wdioHooks = async () => {
await launch(
'wdioHooks',
path.resolve(__dirname, 'helpers', 'hooks.conf.js'),
{
specs: [path.resolve(__dirname, 'mocha', 'wdio_hooks.js')]
}
)
}
/**
* multiremote wdio testrunner tests
*/
const multiremote = async () => {
await launch('multiremote', baseConfig, {
specs: [path.resolve(__dirname, 'multiremote', 'test.js')],
capabilities: {
browserA: {
capabilities: { browserName: 'chrome' }
},
browserB: {
capabilities: { browserName: 'chrome' }
}
}
})
}
/**
* parallel multiremote wdio testrunner tests
*/
const parallelMultiremote = async () => {
console.log(parallelMultiRemoteBaseConfig)
await launch('parallelMultiremote', parallelMultiRemoteBaseConfig, {
specs: [path.resolve(__dirname, 'multiremote', 'test.js')],
})
}
/**
* specfile-level retries (fail)
*/
const retryFail = async () => {
const retryFailed = await launch('retryFailed', baseConfig, {
specs: [path.resolve(__dirname, 'mocha', 'retry_and_fail.js')],
specFileRetries: 1
}).then(
() => false,
() => true
)
assert.equal(retryFailed, true, 'Expected retries to fail but they passed')
}
/**
* specfile-level retries (pass)
*/
const retryPass = async () => {
const retryFilename = path.join(__dirname, '.retry_succeeded')
const logfiles = ['wdio-0-0.log', 'wdio-0-1.log'].map(f => path.join(__dirname, f))
const rmfiles = [retryFilename, ...logfiles]
for (const filename of rmfiles) {
if (await fileExists(filename)) {
fs.unlink(filename, err => {
if (err) {
throw Error(`Unable to delete ${filename}`)
}
})
}
}
await launch('retryPass', baseConfig, {
specs: [path.resolve(__dirname, 'mocha', 'retry_and_pass.js')],
outputDir: path.dirname(logfiles[0]),
specFileRetries: 1,
specFileRetriesDelay: 1,
retryFilename
})
if (!await fileExists(logfiles[0])) {
throw Error(`Expected ${logfiles[0]} to exist but it does not`)
}
if (await fileExists(logfiles[1])) {
throw Error(`Expected ${logfiles[1]} to not exist but it does`)
}
}
/**
* wdio-shared-store-service tests
*/
const sharedStoreServiceTest = async () => {
/**
* assertion fails in Windows
* ToDo(Christian): fix
*/
if (process.platform === 'win32') {
return
}
await launch(
'sharedStoreServiceTest',
path.resolve(__dirname, 'helpers', 'shared-store.conf.js'),
{
specs: [path.resolve(__dirname, 'mocha', 'shared-store-service.js')]
}
)
}
/**
* Mocha with specFiltering feature enabled
*/
const mochaSpecFiltering = async () => {
const { skippedSpecs } = await launch('mochaSpecFiltering', baseConfig, {
specs: [
path.resolve(__dirname, 'mocha', 'test-empty.js'),
path.resolve(__dirname, 'mocha', 'test-skipped.ts'),
path.resolve(__dirname, 'mocha', 'test-skipped-grep.js')
]
})
assert.strictEqual(skippedSpecs, 2)
}
/**
* Jasmine with specFiltering feature enabled
*/
const jasmineSpecFiltering = async () => {
const { skippedSpecs } = await launch('jasmineSpecFiltering', baseConfig, {
specs: [
path.resolve(__dirname, 'jasmine', 'test-empty.js'),
path.resolve(__dirname, 'jasmine', 'test-skipped.js'),
path.resolve(__dirname, 'jasmine', 'test-skipped-grep.js')
],
framework: 'jasmine'
})
assert.strictEqual(skippedSpecs, 2)
}
/**
* Mocha with spec grouping feature enabled
*/
const mochaSpecGrouping = async () => {
const { skippedSpecs } = await launch('mochaSpecGrouping', baseConfig, {
specs: [
[
path.resolve(__dirname, 'mocha', 'test-empty.js'),
path.resolve(__dirname, 'mocha', 'test-middleware.js'),
path.resolve(__dirname, 'mocha', 'test-waitForElement.js'),
path.resolve(__dirname, 'mocha', 'test-skipped.js'),
path.resolve(__dirname, 'mocha', 'test-skipped-grep.js')
]
]
})
// Specs will be treated as a group, so no specs will be skipped
assert.strictEqual(skippedSpecs, 0)
}
/**
* Mocha wdio testrunner tests
*/
const standaloneTest = async () => {
const { skippedSpecs } = await launch(
'standaloneTest',
path.resolve(__dirname, 'helpers', 'async.config.js'),
{
specs: [path.resolve(__dirname, 'mocha', 'standalone.js')]
}
)
assert.strictEqual(skippedSpecs, 0)
}
const severeErrorTest = async () => {
const onPrepareFailed = await launch('severeErrorTest - onPrepareFailed', baseConfig, {
specs: [path.resolve(__dirname, 'mocha', 'test-empty.js')],
onPrepare: () => { throw new SevereServiceError('ups') }
}).then(() => false, () => true)
assert.equal(onPrepareFailed, true, 'Expected onPrepare to fail testrun')
const onWorkerStartFailed = await launch('severeErrorTest - onWorkerStartFailed', baseConfig, {
specs: [path.resolve(__dirname, 'mocha', 'test-empty.js')],
onWorkerStart: () => { throw new SevereServiceError('ups') }
}).then(() => false, () => true)
assert.equal(onWorkerStartFailed, true, 'Expected onWorkerStart to fail testrun')
const onWorkerEndFailed = await launch('severeErrorTest - onWorkerEndFailed', baseConfig, {
specs: [path.resolve(__dirname, 'mocha', 'test-empty.js')],
onWorkerEnd: () => { throw new SevereServiceError('ups') }
}).then(() => false, () => true)
assert.equal(onWorkerEndFailed, true, 'Expected onWorkerStart to fail testrun')
const onCompleteFailed = await launch('severeErrorTest - onCompleteFailed', baseConfig, {
specs: [path.resolve(__dirname, 'mocha', 'test-empty.js')],
onComplete: () => { throw new SevereServiceError('ups') }
}).then(() => false, () => true)
assert.equal(onCompleteFailed, true, 'Expected onWorkerStart to fail testrun')
}
/**
* test usage of globals package
*/
const nonGlobalTestrunner = async () => {
const hasFailed = await launch('nonGlobalTestrunner', baseConfig, {
specs: [path.resolve(__dirname, 'mocha', 'noGlobals.ts')],
injectGlobals: false
}).then(() => false, () => true)
assert.strictEqual(hasFailed, false)
}
/**
* Mocha wdio testrunner skip tests via wdio hook
*/
const mochaHooksTestrunner = async () => {
const { skippedSpecs } = await launch(
'mochaHooksTestrunner',
path.resolve(__dirname, 'helpers', 'mocha-hooks.conf.js'),
{
specs: [
path.resolve(__dirname, 'mocha', 'test-skipped-hooks.ts'),
]
}
)
assert.strictEqual(skippedSpecs, 0)
}
// ****************************
// *** Tests for CLI --spec ***
// ****************************
const runSpecsWithFlagAllPassed = async () => {
const { passed, skippedSpecs } = await launch(
'runSpecsWithFlagAllPassed',
path.resolve(allPassedConfig),
{
spec: ['test']
}
)
assert.strictEqual(passed, 4)
assert.strictEqual(skippedSpecs, 0)
}
const runSpecsWithFlagSeveralPassed = async () => {
const { passed, skippedSpecs } = await launch(
'runSpecsWithFlagSeveralPassed',
path.resolve(severalPassedConfig),
{
spec: ['mocha']
}
)
assert.strictEqual(passed, 4)
assert.strictEqual(skippedSpecs, 0)
}
const runSpecsWithFlagDirectPath = async () => {
const { passed, skippedSpecs } = await launch(
'runSpecsWithFlagDirectPath',
path.resolve(severalPassedConfig),
{
spec: ['./tests/tests-cli-spec-arg/mocha.test03.js']
}
)
assert.strictEqual(passed, 1)
assert.strictEqual(skippedSpecs, 0)
}
const runSpecsWithFlagNoArg = async () => {
const { passed, skippedSpecs } = await launch(
'runSpecsWithFlagNoArg',
path.resolve(noArgConfig),
{
spec: []
}
)
assert.strictEqual(passed, 3)
assert.strictEqual(skippedSpecs, 0)
}
const cliExcludeParamValidationAllExcludedByKeyword = async () => {
const { passed, skippedSpecs, failed } = await launch(
'cliExcludeParamValidationAllExcludedByKeyword',
path.resolve(__dirname, 'tests-cli-exclude-arg/wdio.conf.js'),
{
exclude: ['general']
}
).catch((err) => err) // expected error
assert.strictEqual(passed, undefined)
assert.strictEqual(skippedSpecs, undefined)
assert.strictEqual(failed, undefined)
}
const cliExcludeParamValidationSomeExcludedByKeyword = async () => {
const { passed, skippedSpecs, failed } = await launch(
'cliExcludeParamValidationSomeExcludedByKeyword',
path.resolve(__dirname, 'tests-cli-exclude-arg/wdio.conf.js'),
{
exclude: ['general2']
}
)
assert.strictEqual(passed, 2)
assert.strictEqual(skippedSpecs, 0)
assert.strictEqual(failed, 0)
}
const cliExcludeParamValidationSomeExcludedByPath = async () => {
const { passed, skippedSpecs, failed } = await launch(
'cliExcludeParamValidationSomeExcludedByPath',
path.resolve(__dirname, 'tests-cli-exclude-arg/wdio.conf.js'),
{
exclude: ['./general.test.js']
}
)
assert.strictEqual(passed, 2)
assert.strictEqual(skippedSpecs, 0)
assert.strictEqual(failed, 0)
}
const cliExcludeParamValidationExcludeNonExistentByKeyword = async () => {
const { passed, skippedSpecs, failed } = await launch(
'cliExcludeParamValidationExcludeNonExistentByKeyword',
path.resolve(__dirname, 'tests-cli-exclude-arg/wdio.conf.js'),
{
exclude: ['newgeneral']
}
)
assert.strictEqual(passed, 3)
assert.strictEqual(skippedSpecs, 0)
assert.strictEqual(failed, 0)
}
const cliExcludeParamValidationExcludeFromConfigByKeyword = async () => {
const { passed, skippedSpecs, failed } = await launch(
'cliExcludeParamValidationExcludeFromConfigByKeyword',
path.resolve(__dirname, 'tests-cli-exclude-arg/wdio.with-exclude-prop.conf.js')
)
assert.strictEqual(passed, 2)
assert.strictEqual(skippedSpecs, 0)
assert.strictEqual(failed, 0)
}
const cliExcludeParamValidationExcludeMultipleSpecsByPath = async () => {
const { passed, skippedSpecs, failed } = await launch(
'cliExcludeParamValidationExcludeMultipleSpecsByPath',
path.resolve(__dirname, 'tests-cli-exclude-arg/wdio.conf.js'),
{
exclude: [
'./general.test.js',
'./general2.test.js'
]
}
)
assert.strictEqual(passed, 1)
assert.strictEqual(skippedSpecs, 0)
assert.strictEqual(failed, 0)
}
// *** END - tests for CLI --spec ***
// *************************
// *** Tests for Jasmine ***
// *************************
const jasmineHooksTestrunner = async () => {
const logFile = path.join(__dirname, 'jasmineHooksTestrunner.spec.log')
await launch('jasmineHooksTestrunner',
path.resolve(__dirname, 'helpers', 'jasmine-hooks.conf.js'),
{
specs: [path.resolve(__dirname, 'jasmine', 'test-skipped-hooks.ts')],
reporters: [
['spec', {
outputDir: __dirname,
stdout: false,
logFile
}]
],
framework: 'jasmine',
}).catch((err) => err) // error expected
// eslint-disable-next-line no-control-regex
const specLogs = (await fs.readFile(logFile)).toString().replace(/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g, '')
assert.ok(
specLogs.includes('skip test'),
)
}
const jasmineAfterHookArgsValidation = async () => {
const expectedPassedTestResultPath = path.join(__dirname, 'helpers', 'jasmine-after-hook-validation', 'expected-results', 'expectedTestPassed.json')
const expectedFailedTestResultPath = path.join(__dirname, 'helpers', 'jasmine-after-hook-validation', 'expected-results', 'expectedTestFailed.json')
// Actual test results are written to files in tests\helpers\jasmine.after-hook-validation.conf.js - afterTest()
const actualPassedTestResultPath = path.join(__dirname, 'helpers', 'actualResultsPassed.log')
const actualFailedTestResultPath = path.join(__dirname, 'helpers', 'actualResultsFailed.log')
await launch('jasmineAfterHookArgsValidation',
path.resolve(__dirname, 'helpers', 'jasmine.after-hook-validation.conf.js'),
{
specs: [
path.resolve(__dirname, 'jasmine', 'test.after-hook-validation.ts')
]
}).catch((err) => err) // error expected
const actualPassedTestLogs = JSON.parse((await fs.readFile(actualPassedTestResultPath)))
const actualFailedTestLogs = JSON.parse((await fs.readFile(actualFailedTestResultPath)))
const expectedPassedTestLogs = JSON.parse((await fs.readFile(expectedPassedTestResultPath)))
const expectedFailedTestLogs = JSON.parse((await fs.readFile(expectedFailedTestResultPath)))
// Check before removing
assert.equal(typeof actualPassedTestLogs.test.start, 'number')
assert.equal(typeof actualPassedTestLogs.result.start, 'number')
assert.equal(typeof actualPassedTestLogs.duration, 'number')
assert.equal(typeof actualFailedTestLogs.test.start, 'number')
assert.equal(typeof actualFailedTestLogs.duration, 'number')
assert.equal(typeof actualFailedTestLogs.test.failedExpectations[0].stack, 'string')
assert.equal(typeof actualFailedTestLogs.result.failedExpectations[0].stack, 'string')
assert.equal(typeof actualFailedTestLogs.result.start, 'number')
assert.equal(typeof actualFailedTestLogs.error.stack, 'string')
// Remove dynamic values that will be different every time you run tests, e.g. start time or filepaths
delete actualPassedTestLogs.test.start
delete actualPassedTestLogs.test.filename
delete actualPassedTestLogs.result.start
delete actualPassedTestLogs.result.filename
delete actualPassedTestLogs.duration
delete actualFailedTestLogs.test.start
delete actualFailedTestLogs.test.filename
delete actualFailedTestLogs.test.failedExpectations[0].stack
delete actualFailedTestLogs.error.stack
delete actualFailedTestLogs.result.start
delete actualFailedTestLogs.result.filename
delete actualFailedTestLogs.result.failedExpectations[0].stack
delete actualFailedTestLogs.duration
assert.deepStrictEqual(actualPassedTestLogs, expectedPassedTestLogs)
assert.deepStrictEqual(actualFailedTestLogs, expectedFailedTestLogs)
}
// *** END - Tests for Jasmine ***
(async () => {
const smokeTests = [
mochaTestrunner,
jasmineTestrunner,
multiremote,
parallelMultiremote,
wdioHooks,
cjsTestrunner,
sharedStoreServiceTest,
mochaSpecGrouping,
cucumberTestrunner,
cucumberTestrunnerByLineNumber,
cucumberFailAmbiguousDefinitions,
cucumberReporter,
standaloneTest,
mochaAsyncTestrunner,
customService,
customCJSService,
mochaSpecFiltering,
jasmineSpecFiltering,
jasmineReporter,
jasmineTimeout,
jasmineAfterAll,
jasmineFailSpecWithNoExpectations,
retryFail,
retryPass,
customReporterString,
customReporterObject,
severeErrorTest,
nonGlobalTestrunner,
mochaHooksTestrunner,
runSpecsWithFlagAllPassed,
runSpecsWithFlagSeveralPassed,
runSpecsWithFlagDirectPath,
runSpecsWithFlagNoArg,
jasmineHooksTestrunner,
jasmineAfterHookArgsValidation,
cliExcludeParamValidationAllExcludedByKeyword,
cliExcludeParamValidationSomeExcludedByKeyword,
cliExcludeParamValidationSomeExcludedByPath,
cliExcludeParamValidationExcludeNonExistentByKeyword,
cliExcludeParamValidationExcludeFromConfigByKeyword,
cliExcludeParamValidationExcludeMultipleSpecsByPath
]
console.log('\nRunning smoke tests...\n')
await runTests(smokeTests)
console.log('\nAll smoke tests passed!\n')
process.exit(0)
})().catch((e) => {
// eslint-disable-next-line no-console
console.log(e.stack)
process.exit(1)
})