|
| 1 | +import deepmerge from 'deepmerge'; |
| 2 | + |
1 | 3 | import any from '@travi/any'; |
2 | 4 | import {it, expect, describe, vi, beforeEach} from 'vitest'; |
3 | 5 | import {when} from 'vitest-when'; |
4 | 6 |
|
5 | 7 | import {scaffold as scaffoldUnitTesting} from './unit/index.js'; |
| 8 | +import {scaffold as scaffoldIntegrationTesting} from './integration/index.js'; |
6 | 9 | import scaffoldTesting from './scaffolder.js'; |
7 | 10 |
|
| 11 | +vi.mock('deepmerge'); |
8 | 12 | vi.mock('./unit/index.js'); |
| 13 | +vi.mock('./integration/index.js'); |
9 | 14 |
|
10 | 15 | describe('testing scaffolder', () => { |
11 | 16 | const projectRoot = any.string(); |
12 | 17 | const dialect = any.word(); |
13 | | - const unitTestingDevDependencies = any.listOf(any.string); |
14 | | - const unitTestNextSteps = any.listOf(any.simpleObject); |
15 | | - const unitTestScripts = any.simpleObject(); |
16 | | - const unitTestFilesToIgnoreFromVcs = any.listOf(any.string); |
17 | | - const unitTestDirectoriesToIgnoreFromVcs = any.listOf(any.string); |
18 | 18 | const unitTestFrameworks = any.simpleObject(); |
| 19 | + const integrationTestFrameworks = any.simpleObject(); |
19 | 20 | const decisions = any.simpleObject(); |
| 21 | + const unitTestScaffoldResults = any.simpleObject(); |
| 22 | + const integrationTestScaffoldResults = any.simpleObject(); |
| 23 | + const mergedResults = any.simpleObject(); |
20 | 24 |
|
21 | 25 | beforeEach(() => { |
22 | 26 | when(scaffoldUnitTesting) |
23 | 27 | .calledWith({projectRoot, frameworks: unitTestFrameworks, decisions, dialect}) |
24 | | - .thenResolve({ |
25 | | - dependencies: {javascript: {development: unitTestingDevDependencies}}, |
26 | | - scripts: unitTestScripts, |
27 | | - vcsIgnore: {files: unitTestFilesToIgnoreFromVcs, directories: unitTestDirectoriesToIgnoreFromVcs}, |
28 | | - nextSteps: unitTestNextSteps |
29 | | - }); |
| 28 | + .thenResolve(unitTestScaffoldResults); |
| 29 | + when(scaffoldIntegrationTesting) |
| 30 | + .calledWith({projectRoot, frameworks: integrationTestFrameworks, decisions, dialect}) |
| 31 | + .thenResolve(integrationTestScaffoldResults); |
30 | 32 | }); |
31 | 33 |
|
32 | 34 | it('should scaffold unit testing if the project will be unit test', async () => { |
| 35 | + when(deepmerge.all) |
| 36 | + .calledWith([ |
| 37 | + {dependencies: {javascript: {development: ['@travi/any']}}, eslint: {}}, |
| 38 | + unitTestScaffoldResults, |
| 39 | + {} |
| 40 | + ]) |
| 41 | + .thenReturn(mergedResults); |
| 42 | + |
33 | 43 | expect(await scaffoldTesting({ |
34 | 44 | projectRoot, |
35 | | - tests: {unit: true}, |
| 45 | + tests: {unit: true, integration: false}, |
36 | 46 | unitTestFrameworks, |
| 47 | + integrationTestFrameworks, |
37 | 48 | decisions, |
38 | 49 | dialect |
39 | | - })).toEqual({ |
40 | | - dependencies: {javascript: {development: ['@travi/any', ...unitTestingDevDependencies]}}, |
41 | | - scripts: unitTestScripts, |
42 | | - vcsIgnore: {files: unitTestFilesToIgnoreFromVcs, directories: unitTestDirectoriesToIgnoreFromVcs}, |
43 | | - eslint: {}, |
44 | | - nextSteps: unitTestNextSteps |
45 | | - }); |
| 50 | + })).toEqual(mergedResults); |
46 | 51 | }); |
47 | 52 |
|
48 | | - it('should not scaffold unit testing if the project will not be unit tested', async () => { |
49 | | - expect(await scaffoldTesting({projectRoot, tests: {unit: false, integration: true}})) |
50 | | - .toEqual({dependencies: {javascript: {development: ['@travi/any']}}, eslint: {}}); |
| 53 | + it('should scaffold integration testing if the project will be integration tested', async () => { |
| 54 | + when(deepmerge.all) |
| 55 | + .calledWith([ |
| 56 | + {dependencies: {javascript: {development: ['@travi/any']}}, eslint: {}}, |
| 57 | + {}, |
| 58 | + integrationTestScaffoldResults |
| 59 | + ]) |
| 60 | + .thenReturn(mergedResults); |
| 61 | + |
| 62 | + expect(await scaffoldTesting({ |
| 63 | + projectRoot, |
| 64 | + tests: {unit: false, integration: true}, |
| 65 | + unitTestFrameworks, |
| 66 | + integrationTestFrameworks, |
| 67 | + decisions, |
| 68 | + dialect |
| 69 | + })).toEqual(mergedResults); |
| 70 | + }); |
| 71 | + |
| 72 | + it('should scaffold both unit testing and integration testing if both layers are planned', async () => { |
| 73 | + when(deepmerge.all) |
| 74 | + .calledWith([ |
| 75 | + {dependencies: {javascript: {development: ['@travi/any']}}, eslint: {}}, |
| 76 | + unitTestScaffoldResults, |
| 77 | + integrationTestScaffoldResults |
| 78 | + ]) |
| 79 | + .thenReturn(mergedResults); |
| 80 | + |
| 81 | + expect(await scaffoldTesting({ |
| 82 | + projectRoot, |
| 83 | + tests: {unit: true, integration: true}, |
| 84 | + unitTestFrameworks, |
| 85 | + integrationTestFrameworks, |
| 86 | + decisions, |
| 87 | + dialect |
| 88 | + })).toEqual(mergedResults); |
51 | 89 | }); |
52 | 90 |
|
53 | 91 | it('should not scaffold testing if the project will not be tested', async () => { |
| 92 | + when(deepmerge.all) |
| 93 | + .calledWith([{dependencies: {javascript: {development: []}}, eslint: {}}, {}, {}]) |
| 94 | + .thenReturn(mergedResults); |
| 95 | + |
54 | 96 | expect(await scaffoldTesting({projectRoot, tests: {unit: false, integration: false}})) |
55 | | - .toEqual({dependencies: {javascript: {development: []}}, eslint: {}}); |
| 97 | + .toEqual(mergedResults); |
56 | 98 | }); |
57 | 99 | }); |
0 commit comments