@servicetitan/startup 22.14.0 → 22.16.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.
- package/dist/cli/__mocks__/create-package.d.ts +3 -0
- package/dist/cli/__mocks__/create-package.d.ts.map +1 -0
- package/dist/cli/__mocks__/create-package.js +9 -0
- package/dist/cli/__mocks__/create-package.js.map +1 -0
- package/dist/cli/__mocks__/index.d.ts +2 -0
- package/dist/cli/__mocks__/index.d.ts.map +1 -0
- package/dist/cli/__mocks__/index.js +18 -0
- package/dist/cli/__mocks__/index.js.map +1 -0
- package/dist/cli/commands/eslint.d.ts +12 -0
- package/dist/cli/commands/eslint.d.ts.map +1 -0
- package/dist/cli/commands/eslint.js +47 -0
- package/dist/cli/commands/eslint.js.map +1 -0
- package/dist/cli/commands/index.d.ts +1 -0
- package/dist/cli/commands/index.d.ts.map +1 -1
- package/dist/cli/commands/index.js +1 -0
- package/dist/cli/commands/index.js.map +1 -1
- package/dist/cli/commands/lint.d.ts +5 -0
- package/dist/cli/commands/lint.d.ts.map +1 -1
- package/dist/cli/commands/lint.js +22 -30
- package/dist/cli/commands/lint.js.map +1 -1
- package/dist/cli/index.js +20 -6
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/utils/eslint.d.ts +7 -0
- package/dist/cli/utils/eslint.d.ts.map +1 -0
- package/dist/cli/utils/eslint.js +57 -0
- package/dist/cli/utils/eslint.js.map +1 -0
- package/dist/cli/utils/index.d.ts +2 -0
- package/dist/cli/utils/index.d.ts.map +1 -1
- package/dist/cli/utils/index.js +2 -0
- package/dist/cli/utils/index.js.map +1 -1
- package/dist/cli/utils/set-node-options.d.ts +7 -0
- package/dist/cli/utils/set-node-options.d.ts.map +1 -0
- package/dist/cli/utils/set-node-options.js +46 -0
- package/dist/cli/utils/set-node-options.js.map +1 -0
- package/dist/cli/utils/tcm.d.ts.map +1 -1
- package/dist/cli/utils/tcm.js +3 -1
- package/dist/cli/utils/tcm.js.map +1 -1
- package/dist/utils/get-configuration.d.ts +5 -1
- package/dist/utils/get-configuration.d.ts.map +1 -1
- package/dist/utils/get-configuration.js +2 -2
- package/dist/utils/get-configuration.js.map +1 -1
- package/dist/utils/get-jest-config.d.ts +1 -1
- package/dist/utils/get-jest-config.d.ts.map +1 -1
- package/dist/utils/get-jest-config.js +8 -6
- package/dist/utils/get-jest-config.js.map +1 -1
- package/dist/utils/get-package-data.js +3 -3
- package/dist/utils/get-package-data.js.map +1 -1
- package/dist/utils/get-package-name.d.ts.map +1 -1
- package/dist/utils/get-package-name.js +2 -2
- package/dist/utils/get-package-name.js.map +1 -1
- package/dist/utils/get-packages.js +8 -7
- package/dist/utils/get-packages.js.map +1 -1
- package/dist/webpack/shared.config.d.ts.map +1 -1
- package/dist/webpack/shared.config.js +1 -0
- package/dist/webpack/shared.config.js.map +1 -1
- package/package.json +4 -4
- package/src/cli/__mocks__/create-package.ts +12 -0
- package/src/cli/__mocks__/index.ts +1 -0
- package/src/cli/commands/__tests__/build.test.ts +135 -0
- package/src/cli/commands/__tests__/bundle-package.test.ts +72 -0
- package/src/cli/commands/__tests__/eslint.test.ts +19 -0
- package/src/cli/commands/__tests__/init.test.ts +42 -0
- package/src/cli/commands/__tests__/lint.test.ts +114 -0
- package/src/cli/commands/__tests__/mfe-package-clean.test.ts +193 -0
- package/src/cli/commands/__tests__/mfe-package-publish.test.ts +192 -0
- package/src/cli/commands/__tests__/mfe-publish.test.ts +172 -0
- package/src/cli/commands/__tests__/prepare-package.test.ts +75 -0
- package/src/cli/commands/__tests__/start.test.ts +111 -0
- package/src/cli/commands/__tests__/styles-check.test.ts +119 -0
- package/src/cli/commands/__tests__/tests.test.ts +43 -0
- package/src/cli/commands/eslint.ts +19 -0
- package/src/cli/commands/index.ts +1 -0
- package/src/cli/commands/lint.ts +29 -42
- package/src/cli/index.ts +17 -5
- package/src/cli/utils/__tests__/assets-copy.test.ts +48 -52
- package/src/cli/utils/__tests__/bundle.test.ts +361 -0
- package/src/cli/utils/__tests__/cli-git.test.ts +28 -0
- package/src/cli/utils/__tests__/cli-npm.test.ts +166 -0
- package/src/cli/utils/__tests__/cli-os.test.ts +103 -0
- package/src/cli/utils/__tests__/eslint.test.ts +91 -0
- package/src/cli/utils/__tests__/get-module-type.test.ts +56 -0
- package/src/cli/utils/__tests__/is-module-installed.test.ts +24 -0
- package/src/cli/utils/__tests__/set-node-options.test.ts +131 -0
- package/src/cli/utils/__tests__/styles-copy.test.ts +48 -44
- package/src/cli/utils/__tests__/tcm.test.ts +101 -192
- package/src/cli/utils/__tests__/tsc.test.ts +85 -0
- package/src/cli/utils/eslint.ts +50 -0
- package/src/cli/utils/index.ts +2 -0
- package/src/cli/utils/set-node-options.ts +45 -0
- package/src/cli/utils/tcm.ts +3 -1
- package/src/utils/__tests__/get-configuration.test.ts +215 -16
- package/src/utils/__tests__/get-destination-folders.test.ts +65 -0
- package/src/utils/__tests__/get-jest-config.test.ts +134 -0
- package/src/utils/__tests__/get-package-data.test.ts +90 -0
- package/src/utils/__tests__/get-packages.test.ts +165 -0
- package/src/utils/__tests__/get-tsconfig.test.ts +48 -0
- package/src/utils/__tests__/log.test.ts +123 -0
- package/src/utils/__tests__/to-array.test.ts +19 -0
- package/src/utils/get-configuration.ts +8 -3
- package/src/utils/get-jest-config.ts +3 -1
- package/src/utils/get-package-data.ts +1 -1
- package/src/utils/get-package-name.ts +1 -2
- package/src/utils/get-packages.ts +2 -2
- package/src/webpack/shared.config.ts +1 -0
- package/template/package.json +8 -1
- package/template/packages/application/package.json +5 -0
- package/template/packages/application/src/__tests__/app.test.tsx +33 -0
- package/template/packages/application/src/app.tsx +9 -6
- package/template/packages/application/src/main-page.tsx +5 -0
- package/template/packages/application/src/second-page.tsx +5 -0
- package/template/setupTests.ts +27 -0
- package/template/tsconfig.test.json +1 -1
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import mockFS from 'mock-fs';
|
|
2
|
+
import { ESLint } from 'eslint';
|
|
3
|
+
|
|
4
|
+
import { eslint } from '../eslint';
|
|
5
|
+
|
|
6
|
+
jest.mock('eslint');
|
|
7
|
+
|
|
8
|
+
describe(`[startup] utils:${eslint.name}`, () => {
|
|
9
|
+
const mockResult = { filePath: 'foo' } as ESLint.LintResult;
|
|
10
|
+
|
|
11
|
+
let mockESLint: Partial<ESLint>;
|
|
12
|
+
let eslintArgs: Parameters<typeof eslint>[0];
|
|
13
|
+
let eslintResults: ESLint.LintResult[];
|
|
14
|
+
let eslintErrors: ESLint.LintResult[];
|
|
15
|
+
|
|
16
|
+
beforeEach(() => jest.resetAllMocks());
|
|
17
|
+
|
|
18
|
+
beforeEach(() => {
|
|
19
|
+
mockESLint = {
|
|
20
|
+
lintFiles: jest.fn(() => Promise.resolve(eslintResults)),
|
|
21
|
+
loadFormatter: () => Promise.resolve({ format: () => '' }),
|
|
22
|
+
};
|
|
23
|
+
(ESLint as any).mockImplementation(() => mockESLint);
|
|
24
|
+
ESLint.getErrorResults = jest.fn(() => eslintErrors);
|
|
25
|
+
ESLint.outputFixes = jest.fn();
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
beforeEach(() => {
|
|
29
|
+
eslintArgs = { paths: ['foo', 'bar'] };
|
|
30
|
+
eslintResults = [mockResult];
|
|
31
|
+
eslintErrors = [];
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
const subject = async () => eslint(eslintArgs);
|
|
35
|
+
|
|
36
|
+
test('lints .ts and .tsx files', async () => {
|
|
37
|
+
await subject();
|
|
38
|
+
|
|
39
|
+
expect(ESLint).toHaveBeenCalledWith(
|
|
40
|
+
expect.objectContaining({
|
|
41
|
+
extensions: ['.ts', '.tsx'],
|
|
42
|
+
})
|
|
43
|
+
);
|
|
44
|
+
expect(mockESLint.lintFiles).toHaveBeenCalledWith(eslintArgs.paths);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
describe('when instructed to fix issues', () => {
|
|
48
|
+
beforeEach(() => (eslintArgs.fix = true));
|
|
49
|
+
|
|
50
|
+
test('applies fixes', async () => {
|
|
51
|
+
await subject();
|
|
52
|
+
|
|
53
|
+
expect(ESLint.outputFixes).toHaveBeenCalledWith(eslintResults);
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
describe('when there are errors', () => {
|
|
58
|
+
beforeEach(() => (eslintErrors = [mockResult]));
|
|
59
|
+
|
|
60
|
+
test('sets process exitCode', async () => {
|
|
61
|
+
await subject();
|
|
62
|
+
|
|
63
|
+
expect(process.exitCode).toBeGreaterThan(0);
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
describe('with no paths', () => {
|
|
68
|
+
beforeEach(() => (eslintArgs.paths = []));
|
|
69
|
+
|
|
70
|
+
test('lints the current directory', async () => {
|
|
71
|
+
await subject();
|
|
72
|
+
|
|
73
|
+
expect(mockESLint.lintFiles).toHaveBeenCalledWith([process.cwd()]);
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
describe('when disabled', () => {
|
|
78
|
+
const config = JSON.stringify({
|
|
79
|
+
cli: { lint: { eslint: { disabled: true } } },
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
beforeEach(() => mockFS({ 'package.json': config }));
|
|
83
|
+
afterEach(() => mockFS.restore());
|
|
84
|
+
|
|
85
|
+
test('does nothing', async () => {
|
|
86
|
+
await subject();
|
|
87
|
+
|
|
88
|
+
expect(mockESLint.lintFiles).not.toHaveBeenCalled();
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
});
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import mockFS from 'mock-fs';
|
|
2
|
+
import { getModuleType } from '../get-module-type';
|
|
3
|
+
|
|
4
|
+
describe('[startup] Cli Utils', () => {
|
|
5
|
+
describe(`${getModuleType.name}`, () => {
|
|
6
|
+
const tsconfig = 'tsconfig.json';
|
|
7
|
+
|
|
8
|
+
beforeEach(() => mockFS({ [tsconfig]: JSON.stringify({}) }));
|
|
9
|
+
|
|
10
|
+
afterEach(() => mockFS.restore());
|
|
11
|
+
|
|
12
|
+
const subject = (configPath?: string) => getModuleType(configPath ?? `./${tsconfig}`);
|
|
13
|
+
|
|
14
|
+
test('returns commonjs', () => {
|
|
15
|
+
expect(subject()).toBe('commonjs');
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
describe('when config file contains compilerOptions.module', () => {
|
|
19
|
+
const module = 'foo';
|
|
20
|
+
|
|
21
|
+
beforeEach(() => {
|
|
22
|
+
mockFS({ [tsconfig]: JSON.stringify({ compilerOptions: { module } }) });
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
test('returns configured module', () => {
|
|
26
|
+
expect(subject()).toBe(module);
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
describe('when config extends another', () => {
|
|
31
|
+
const module = 'bar';
|
|
32
|
+
|
|
33
|
+
beforeEach(() => {
|
|
34
|
+
mockFS({
|
|
35
|
+
'tsconfig.json': JSON.stringify({
|
|
36
|
+
extends: '@servicetitan/startup/tsconfig/base',
|
|
37
|
+
}),
|
|
38
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
39
|
+
'node_modules': {
|
|
40
|
+
'@servicetitan': {
|
|
41
|
+
startup: {
|
|
42
|
+
tsconfig: {
|
|
43
|
+
'base.json': JSON.stringify({ compilerOptions: { module } }),
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
test("returns extended config's module", () => {
|
|
52
|
+
expect(subject()).toBe(module);
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
});
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import mockFS from 'mock-fs';
|
|
2
|
+
|
|
3
|
+
import { isModuleInstalled } from '../is-module-installed';
|
|
4
|
+
|
|
5
|
+
describe(`[startup] Cli Utils`, () => {
|
|
6
|
+
describe(`${isModuleInstalled.name}`, () => {
|
|
7
|
+
afterEach(() => mockFS.restore());
|
|
8
|
+
|
|
9
|
+
const subject = (name: string) => isModuleInstalled(name);
|
|
10
|
+
|
|
11
|
+
test('returns false', () => {
|
|
12
|
+
expect(subject('foo')).toBe(false);
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
describe('when module exists', () => {
|
|
16
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
17
|
+
beforeEach(() => mockFS({ node_modules: { bar: { 'index.js': '' } } }));
|
|
18
|
+
|
|
19
|
+
test('returns true', () => {
|
|
20
|
+
expect(subject('bar')).toBe(true);
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
});
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import os from 'os';
|
|
2
|
+
import { getConfiguration } from '../../../utils';
|
|
3
|
+
|
|
4
|
+
import { setNodeOptions } from '../set-node-options';
|
|
5
|
+
|
|
6
|
+
jest.mock('os', () => ({
|
|
7
|
+
totalmem: jest.fn(),
|
|
8
|
+
}));
|
|
9
|
+
|
|
10
|
+
jest.mock('../../../utils', () => ({
|
|
11
|
+
getConfiguration: jest.fn(() => ({})),
|
|
12
|
+
}));
|
|
13
|
+
|
|
14
|
+
describe(`[startup] utils:${setNodeOptions.name}`, () => {
|
|
15
|
+
const MB = 1024 * 1024;
|
|
16
|
+
const DEFAULT_SIZE = 8192;
|
|
17
|
+
const originalNodeOptions = process.env.NODE_OPTIONS;
|
|
18
|
+
const maxOldSpaceSize = `--max_old_space_size=${DEFAULT_SIZE}`;
|
|
19
|
+
const command = 'foo';
|
|
20
|
+
|
|
21
|
+
beforeEach(() => {
|
|
22
|
+
delete process.env.NODE_OPTIONS;
|
|
23
|
+
(os.totalmem as jest.Mock).mockReturnValue(16384 * MB);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
afterAll(() => (process.env.NODE_OPTIONS = originalNodeOptions));
|
|
27
|
+
|
|
28
|
+
const subject = () => setNodeOptions(command);
|
|
29
|
+
|
|
30
|
+
test(`returns true and adds ${maxOldSpaceSize} to process.env.NODE_OPTIONS`, () => {
|
|
31
|
+
expect(subject()).toBe(true);
|
|
32
|
+
|
|
33
|
+
expect(process.env.NODE_OPTIONS).toEqual(maxOldSpaceSize);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
describe('when system has insufficient memory', () => {
|
|
37
|
+
const totalMem = 4096 * MB;
|
|
38
|
+
|
|
39
|
+
beforeEach(() => (os.totalmem as jest.Mock).mockReturnValue(totalMem));
|
|
40
|
+
|
|
41
|
+
test('reduces --max_old_space_size to 512 less than total memory', () => {
|
|
42
|
+
expect(subject()).toBe(true);
|
|
43
|
+
|
|
44
|
+
const match = process.env.NODE_OPTIONS!.match(/max_old_space_size=(?<size>\d+)/);
|
|
45
|
+
expect(Number(match?.groups!.size)).toBe(totalMem / MB - 512);
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
describe('with existing process.env.NODE_OPTIONS', () => {
|
|
50
|
+
const options = '--no-warnings';
|
|
51
|
+
|
|
52
|
+
beforeEach(() => (process.env.NODE_OPTIONS = options));
|
|
53
|
+
|
|
54
|
+
test('prepends --max_old_space_size to existing NODE_OPTIONS', () => {
|
|
55
|
+
expect(subject()).toBe(true);
|
|
56
|
+
|
|
57
|
+
expect(process.env.NODE_OPTIONS).toEqual(`${maxOldSpaceSize} ${options}`);
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
describe('with existing NODE_OPTIONS contains --max_old_space_size', () => {
|
|
62
|
+
const options = '--max_old_space_size=1024';
|
|
63
|
+
|
|
64
|
+
beforeEach(() => (process.env.NODE_OPTIONS = options));
|
|
65
|
+
|
|
66
|
+
test('returns false and does not change NODE_OPTIONS', () => {
|
|
67
|
+
expect(subject()).toBe(false);
|
|
68
|
+
|
|
69
|
+
expect(process.env.NODE_OPTIONS).toEqual(options);
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
describe("when cli's config has NODE_OPTIONS", () => {
|
|
74
|
+
let options: string[];
|
|
75
|
+
|
|
76
|
+
beforeEach(() => {
|
|
77
|
+
options = ['--no-warning', '--test'];
|
|
78
|
+
(getConfiguration as jest.Mock).mockImplementation(() => ({
|
|
79
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
80
|
+
NODE_OPTIONS: options,
|
|
81
|
+
}));
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
test("adds --max_old_space_size to cli's NODE_OPTIONS", () => {
|
|
85
|
+
expect(subject()).toBe(true);
|
|
86
|
+
|
|
87
|
+
expect(process.env.NODE_OPTIONS).toBe(`${maxOldSpaceSize} ${options.join(' ')}`);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
describe("when cli's NODE_OPTIONS contains --max_old_space_size", () => {
|
|
91
|
+
beforeEach(() => options.push('--max_old_space_size=1024'));
|
|
92
|
+
|
|
93
|
+
test("does not change cli's NODE_OPTIONS", () => {
|
|
94
|
+
expect(subject()).toBe(true);
|
|
95
|
+
|
|
96
|
+
expect(process.env.NODE_OPTIONS).toEqual(options.join(' '));
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
describe('with existing process.env.NODE_OPTIONS', () => {
|
|
101
|
+
const envOptions = '--inspect-publish-uid=http';
|
|
102
|
+
|
|
103
|
+
beforeEach(() => (process.env.NODE_OPTIONS = envOptions));
|
|
104
|
+
|
|
105
|
+
test("prepends cli's NODE_OPTIONS to existing NODE_OPTIONS", () => {
|
|
106
|
+
expect(subject()).toBe(true);
|
|
107
|
+
|
|
108
|
+
expect(process.env.NODE_OPTIONS).toEqual(
|
|
109
|
+
[maxOldSpaceSize, ...options, envOptions].join(' ')
|
|
110
|
+
);
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
describe("when command's config has NODE_OPTIONS", () => {
|
|
116
|
+
const options = ['--no-warning', '--test'];
|
|
117
|
+
|
|
118
|
+
beforeEach(() =>
|
|
119
|
+
(getConfiguration as jest.Mock).mockReturnValue({
|
|
120
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
121
|
+
[command]: { NODE_OPTIONS: options },
|
|
122
|
+
})
|
|
123
|
+
);
|
|
124
|
+
|
|
125
|
+
test("adds --max_old_space_size to command's NODE_OPTIONS", () => {
|
|
126
|
+
expect(subject()).toBe(true);
|
|
127
|
+
|
|
128
|
+
expect(process.env.NODE_OPTIONS).toBe(`${maxOldSpaceSize} ${options.join(' ')}`);
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
});
|
|
@@ -1,52 +1,56 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import fs from 'fs';
|
|
4
|
-
import mock from 'mock-fs';
|
|
5
|
-
import { mocked } from 'ts-jest/utils';
|
|
6
|
-
|
|
1
|
+
import cpx from 'cpx';
|
|
7
2
|
import { getFolders } from '../../../utils';
|
|
8
|
-
import { stylesCopy } from '..';
|
|
9
|
-
|
|
10
|
-
describe('[Startup] utils:styles-copy', () => {
|
|
11
|
-
beforeAll(() => {
|
|
12
|
-
mocked(getFolders).mockReturnValue({ source: 'src', destination: 'dist' });
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
afterAll(() => {
|
|
16
|
-
mock.restore();
|
|
17
|
-
});
|
|
18
3
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
4
|
+
import { stylesCopy, stylesCopyWatch } from '../styles-copy';
|
|
5
|
+
import { styleExtensions } from '../index';
|
|
6
|
+
|
|
7
|
+
jest.mock('cpx', () => ({
|
|
8
|
+
copy: jest.fn().mockImplementation((...args: any[]) => {
|
|
9
|
+
const callback = args[args.length - 1];
|
|
10
|
+
callback(null);
|
|
11
|
+
}),
|
|
12
|
+
watch: jest.fn(() => ({ on: (_eventName: string, listener: Function) => listener() })),
|
|
13
|
+
}));
|
|
14
|
+
jest.mock('../../../utils', () => ({
|
|
15
|
+
getFolders: jest.fn(),
|
|
16
|
+
log: { info: jest.fn() }, // suppress log output
|
|
17
|
+
}));
|
|
18
|
+
|
|
19
|
+
describe('[startup] Cli Utils (Styles)', () => {
|
|
20
|
+
const source = 'foo';
|
|
21
|
+
const destination = 'bar';
|
|
22
|
+
|
|
23
|
+
beforeEach(() => jest.mocked(getFolders).mockReturnValue({ source, destination }));
|
|
24
|
+
|
|
25
|
+
describe(`${stylesCopy.name}`, () => {
|
|
26
|
+
const subject = async () => stylesCopy();
|
|
27
|
+
|
|
28
|
+
test('copies styles from source to destination', async () => {
|
|
29
|
+
await subject();
|
|
30
|
+
|
|
31
|
+
expect(cpx.copy).toHaveBeenCalledWith(
|
|
32
|
+
`${source}/**/*.{${styleExtensions.join()}}`,
|
|
33
|
+
destination,
|
|
34
|
+
expect.anything()
|
|
35
|
+
);
|
|
26
36
|
});
|
|
27
|
-
|
|
28
|
-
await stylesCopy();
|
|
29
|
-
|
|
30
|
-
expect(fs.existsSync('./dist/1.css')).toBeTruthy();
|
|
31
|
-
expect(fs.existsSync('./dist/a/2.css')).toBeTruthy();
|
|
32
|
-
expect(fs.existsSync('./dist/b/c/3.css')).toBeTruthy();
|
|
33
37
|
});
|
|
34
38
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
39
|
+
describe(`${stylesCopyWatch.name}`, () => {
|
|
40
|
+
const subject = () => stylesCopyWatch();
|
|
41
|
+
|
|
42
|
+
test('copies styles from source to destination in watch mode', async () => {
|
|
43
|
+
try {
|
|
44
|
+
await subject();
|
|
45
|
+
} catch (error: any) {
|
|
46
|
+
// ignore rejected promise that terminates watch()
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
expect(cpx.watch).toHaveBeenCalledWith(
|
|
50
|
+
`${source}/**/*.{${styleExtensions.join()}}`,
|
|
51
|
+
destination,
|
|
52
|
+
{ initialCopy: false }
|
|
53
|
+
);
|
|
44
54
|
});
|
|
45
|
-
|
|
46
|
-
await stylesCopy();
|
|
47
|
-
|
|
48
|
-
expect(fs.existsSync('./dist/1.css')).toBeTruthy();
|
|
49
|
-
expect(fs.existsSync('./dist/3.scss')).toBeTruthy();
|
|
50
|
-
expect(fs.existsSync('./dist/4.less')).toBeTruthy();
|
|
51
55
|
});
|
|
52
56
|
});
|