just-scripts 2.2.1 → 2.2.3

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,192 +0,0 @@
1
- import * as mockfs from 'mock-fs';
2
- import * as path from 'path';
3
- import * as fs from 'fs';
4
- // import { dirSync, fileSync, DirResult, FileResult } from 'tmp';
5
- import { executeCopyInstructions } from '../executeCopyInstructions';
6
- import { CopyInstruction } from '../CopyInstruction';
7
-
8
- describe('executeCopyInstructions functional tests', () => {
9
- const sourceDir = 'sourceDir';
10
- const sourceFile1 = 'sourceFile1';
11
- const sourceFile2 = 'sourceFile2';
12
- const sourceFilePath1 = path.join(sourceDir, sourceFile1);
13
- const sourceFilePath2 = path.join(sourceDir, sourceFile2);
14
- const sourceFileContents1 = 'source file contents 1';
15
- const sourceFileContents2 = 'source file contents 2';
16
- const destDir = 'destDir';
17
- const destFile = 'destFile';
18
- const destFilePath = path.join(destDir, destFile);
19
-
20
- beforeEach(() => {
21
- mockfs({
22
- [sourceDir]: {
23
- [sourceFile1]: sourceFileContents1,
24
- [sourceFile2]: sourceFileContents2,
25
- },
26
- [destDir]: {},
27
- });
28
- });
29
-
30
- afterEach(() => {
31
- mockfs.restore();
32
- });
33
-
34
- it('executes single source copy instructions (symlink)', async () => {
35
- const copyInstruction: CopyInstruction = {
36
- sourceFilePath: sourceFilePath1,
37
- destinationFilePath: destFilePath,
38
- };
39
-
40
- expect(fs.existsSync(destFilePath)).toBeFalsy();
41
-
42
- await executeCopyInstructions({
43
- copyInstructions: [copyInstruction],
44
- });
45
-
46
- expect(fs.existsSync(destFilePath)).toBeTruthy();
47
- expect(fs.lstatSync(destFilePath).isSymbolicLink()).toBeTruthy();
48
- expect(fs.readFileSync(destFilePath).toString()).toEqual(sourceFileContents1);
49
- });
50
-
51
- it('executes single source (arrayified) copy instructions (copy)', async () => {
52
- const copyInstruction: CopyInstruction = {
53
- sourceFilePath: [sourceFilePath1],
54
- destinationFilePath: destFilePath,
55
- noSymlink: true,
56
- };
57
-
58
- expect(fs.existsSync(destFilePath)).toBeFalsy();
59
-
60
- await executeCopyInstructions({
61
- copyInstructions: [copyInstruction],
62
- });
63
-
64
- expect(fs.existsSync(destFilePath)).toBeTruthy();
65
- expect(fs.lstatSync(destFilePath).isSymbolicLink()).toBeFalsy();
66
- expect(fs.readFileSync(destFilePath).toString()).toEqual(sourceFileContents1);
67
- });
68
-
69
- it('merges output', async () => {
70
- const copyInstruction: CopyInstruction = {
71
- sourceFilePath: [sourceFilePath1, sourceFilePath2],
72
- destinationFilePath: destFilePath,
73
- };
74
-
75
- const expectedOutput = [sourceFileContents1, sourceFileContents2].join('\n');
76
-
77
- expect(fs.existsSync(destFilePath)).toBeFalsy();
78
-
79
- await executeCopyInstructions({
80
- copyInstructions: [copyInstruction],
81
- });
82
-
83
- expect(fs.existsSync(destFilePath)).toBeTruthy();
84
- expect(fs.lstatSync(destFilePath).isSymbolicLink()).toBeFalsy();
85
- expect(fs.readFileSync(destFilePath).toString()).toEqual(expectedOutput);
86
- });
87
-
88
- it('fails to validate merge + symlink copy instruction', async () => {
89
- const copyInstruction: CopyInstruction = {
90
- sourceFilePath: [sourceFilePath1, sourceFilePath2],
91
- destinationFilePath: destFilePath,
92
- noSymlink: false,
93
- };
94
-
95
- const promise = executeCopyInstructions({
96
- copyInstructions: [copyInstruction],
97
- });
98
-
99
- await expect(promise).rejects.toThrow();
100
- });
101
-
102
- /**
103
- * TODO:
104
- * Rationalize and document expected executeCopyInstructions behavior.
105
- * If same source is present twice to same dest file, do we really want output duplicated?
106
- * Fix / change these tests so that they pass after updating code / documentation on expected behavior.
107
- */
108
- // it('does not duplicate output from duplicate source files', async () => {
109
- // const copyInstruction = {
110
- // sourceFilePath: [sourceFilePath, sourceFilePath],
111
- // destinationFilePath: destFilePath
112
- // };
113
-
114
- // expect(fs.existsSync(destFilePath)).toBeFalsy();
115
-
116
- // await executeCopyInstructions({
117
- // copyInstructions: [
118
- // copyInstruction
119
- // ]
120
- // });
121
-
122
- // expect(fs.existsSync(destFilePath)).toBeTruthy();
123
- // expect(fs.readFileSync(destFilePath).toString()).toEqual(sourceFileContents1);
124
- // });
125
- });
126
-
127
- // These tests test scenarios where multiple instructions end up deleting and overwriting the same
128
- // filepath multiple times. They are commented out because they currently fail, generating ENOENT and
129
- // EBUSY exceptions. We may want just to handle these types of conditions eventually, most
130
- // likely by having an optional validation step. Documentation should also be added to executeCopyInstructions
131
- // detailing caution and error scenarios.
132
- // These tests require 'tmp' and '@types/tmp` dev dependencies.
133
- // describe('executeCopyInstructions I/O exception tests', () => {
134
- // let destDir: DirResult;
135
- // let sourceFile: FileResult;
136
- // let sourceNames: string[] = [];
137
-
138
- // beforeEach(() => {
139
- // // unsafeCleanup will clean up directories even when not empty
140
- // destDir = dirSync({ unsafeCleanup: true });
141
- // sourceFile = fileSync();
142
- // });
143
-
144
- // afterEach(() => {
145
- // sourceNames.forEach(name => {
146
- // if (fs.existsSync(name)) {
147
- // fs.unlinkSync(name);
148
- // }
149
- // })
150
- // destDir.removeCallback();
151
- // sourceFile.removeCallback();
152
- // });
153
-
154
- // it('copies duplicate sources to empty dest without generating an exception', async () => {
155
- // const basename = path.basename(sourceFile.name);
156
- // const destinationFilePath = path.join(destDir.name, basename);
157
-
158
- // const copyInstruction = {
159
- // sourceFilePath: sourceFile.name,
160
- // destinationFilePath
161
- // };
162
-
163
- // // Unchecked duplicate copy instructions will cause an EBUSY: resource busy or locked
164
- // // as the copy instructions attempt to write to the same file.
165
- // await executeCopyInstructions({
166
- // copyInstructions: Array(100).fill(copyInstruction)
167
- // });
168
- // });
169
-
170
- // it('copies duplicate sources to dest with pre-existing file without generating an exception', async () => {
171
- // const basename = path.basename(sourceFile.name);
172
- // const destinationFilePath = path.join(destDir.name, basename);
173
-
174
- // const copyInstruction = {
175
- // sourceFilePath: sourceFile.name,
176
- // destinationFilePath
177
- // };
178
-
179
- // // Set up "pre-existing" file in dest first
180
- // await executeCopyInstructions({
181
- // copyInstructions: [
182
- // copyInstruction,
183
- // ]
184
- // });
185
-
186
- // // If file already exists, unchecked duplicate copy instructions will attempt to delete the file
187
- // // when overwriting it, generating an ENOENT: no such file or directory error.
188
- // await executeCopyInstructions({
189
- // copyInstructions: Array(100).fill(copyInstruction)
190
- // });
191
- // });
192
- // });
@@ -1,205 +0,0 @@
1
- // Jest Snapshot v1, https://goo.gl/fbAQLP
2
-
3
- exports[`tscTask using 'tscTask' function with 'build' option where 'build' is custom path and tsconfig.json exists execs expected command 1`] = `
4
- [
5
- "\${nodeExePath}",
6
- "\${repoRoot}/node_modules/typescript/lib/tsc.js",
7
- "--build",
8
- "a/custom/path/tsconfig.json",
9
- ]
10
- `;
11
-
12
- exports[`tscTask using 'tscTask' function with 'build' option where 'build' is multiple paths and they all exist execs expected command 1`] = `
13
- [
14
- "\${nodeExePath}",
15
- "\${repoRoot}/node_modules/typescript/lib/tsc.js",
16
- "--build",
17
- "project/a/tsconfig.json",
18
- "project/b/tsconfig.json",
19
- "project/c/tsconfig.json",
20
- ]
21
- `;
22
-
23
- exports[`tscTask using 'tscTask' function with 'project' option where 'project' is custom path and tsconfig.json exists execs expected command 1`] = `
24
- [
25
- "\${nodeExePath}",
26
- "\${repoRoot}/node_modules/typescript/lib/tsc.js",
27
- "--project",
28
- "a/custom/path/tsconfig.json",
29
- ]
30
- `;
31
-
32
- exports[`tscTask using 'tscTask' function with a boolean 'false' switch execs expected command 1`] = `
33
- [
34
- "\${nodeExePath}",
35
- "\${repoRoot}/node_modules/typescript/lib/tsc.js",
36
- "--project",
37
- "\${packageRoot}/tsconfig.json",
38
- ]
39
- `;
40
-
41
- exports[`tscTask using 'tscTask' function with a boolean 'true' switch execs expected command 1`] = `
42
- [
43
- "\${nodeExePath}",
44
- "\${repoRoot}/node_modules/typescript/lib/tsc.js",
45
- "--allowJs",
46
- "--project",
47
- "\${packageRoot}/tsconfig.json",
48
- ]
49
- `;
50
-
51
- exports[`tscTask using 'tscTask' function with a combination of switches execs expected command 1`] = `
52
- [
53
- "\${nodeExePath}",
54
- "\${repoRoot}/node_modules/typescript/lib/tsc.js",
55
- "--allowJs",
56
- "--build",
57
- "tsconfig.json",
58
- "--outDir",
59
- "some/out/path",
60
- ]
61
- `;
62
-
63
- exports[`tscTask using 'tscTask' function with empty options execs expected command 1`] = `
64
- [
65
- "\${nodeExePath}",
66
- "\${repoRoot}/node_modules/typescript/lib/tsc.js",
67
- "--project",
68
- "\${packageRoot}/tsconfig.json",
69
- ]
70
- `;
71
-
72
- exports[`tscTask using 'tscTask' function with no arguments execs expected command 1`] = `
73
- [
74
- "\${nodeExePath}",
75
- "\${repoRoot}/node_modules/typescript/lib/tsc.js",
76
- "--project",
77
- "\${packageRoot}/tsconfig.json",
78
- ]
79
- `;
80
-
81
- exports[`tscTask using 'tscTask' function with string array option execs expected command 1`] = `
82
- [
83
- "\${nodeExePath}",
84
- "\${repoRoot}/node_modules/typescript/lib/tsc.js",
85
- "--lib",
86
- "es6",
87
- "dom",
88
- "esnext.intl",
89
- "--project",
90
- "\${packageRoot}/tsconfig.json",
91
- ]
92
- `;
93
-
94
- exports[`tscTask using 'tscTask' function with string value option execs expected command 1`] = `
95
- [
96
- "\${nodeExePath}",
97
- "\${repoRoot}/node_modules/typescript/lib/tsc.js",
98
- "--module",
99
- "ESNext",
100
- "--project",
101
- "\${packageRoot}/tsconfig.json",
102
- ]
103
- `;
104
-
105
- exports[`tscTask using 'tscWatchTask' function with 'build' option where 'build' is custom path and tsconfig.json exists execs expected command 1`] = `
106
- [
107
- "\${repoRoot}/node_modules/typescript/lib/tsc.js",
108
- "--build",
109
- "a/custom/path/tsconfig.json",
110
- "--watch",
111
- ]
112
- `;
113
-
114
- exports[`tscTask using 'tscWatchTask' function with 'build' option where 'build' is multiple paths and they all exist execs expected command 1`] = `
115
- [
116
- "\${repoRoot}/node_modules/typescript/lib/tsc.js",
117
- "--build",
118
- "project/a/tsconfig.json",
119
- "project/b/tsconfig.json",
120
- "project/c/tsconfig.json",
121
- "--watch",
122
- ]
123
- `;
124
-
125
- exports[`tscTask using 'tscWatchTask' function with 'project' option where 'project' is custom path and tsconfig.json exists execs expected command 1`] = `
126
- [
127
- "\${repoRoot}/node_modules/typescript/lib/tsc.js",
128
- "--project",
129
- "a/custom/path/tsconfig.json",
130
- "--watch",
131
- ]
132
- `;
133
-
134
- exports[`tscTask using 'tscWatchTask' function with a boolean 'false' switch execs expected command 1`] = `
135
- [
136
- "\${repoRoot}/node_modules/typescript/lib/tsc.js",
137
- "--project",
138
- "\${packageRoot}/tsconfig.json",
139
- "--watch",
140
- ]
141
- `;
142
-
143
- exports[`tscTask using 'tscWatchTask' function with a boolean 'true' switch execs expected command 1`] = `
144
- [
145
- "\${repoRoot}/node_modules/typescript/lib/tsc.js",
146
- "--allowJs",
147
- "--project",
148
- "\${packageRoot}/tsconfig.json",
149
- "--watch",
150
- ]
151
- `;
152
-
153
- exports[`tscTask using 'tscWatchTask' function with a combination of switches execs expected command 1`] = `
154
- [
155
- "\${repoRoot}/node_modules/typescript/lib/tsc.js",
156
- "--allowJs",
157
- "--build",
158
- "tsconfig.json",
159
- "--outDir",
160
- "some/out/path",
161
- "--watch",
162
- ]
163
- `;
164
-
165
- exports[`tscTask using 'tscWatchTask' function with empty options execs expected command 1`] = `
166
- [
167
- "\${repoRoot}/node_modules/typescript/lib/tsc.js",
168
- "--project",
169
- "\${packageRoot}/tsconfig.json",
170
- "--watch",
171
- ]
172
- `;
173
-
174
- exports[`tscTask using 'tscWatchTask' function with no arguments execs expected command 1`] = `
175
- [
176
- "\${repoRoot}/node_modules/typescript/lib/tsc.js",
177
- "--project",
178
- "\${packageRoot}/tsconfig.json",
179
- "--watch",
180
- ]
181
- `;
182
-
183
- exports[`tscTask using 'tscWatchTask' function with string array option execs expected command 1`] = `
184
- [
185
- "\${repoRoot}/node_modules/typescript/lib/tsc.js",
186
- "--lib",
187
- "es6",
188
- "dom",
189
- "esnext.intl",
190
- "--project",
191
- "\${packageRoot}/tsconfig.json",
192
- "--watch",
193
- ]
194
- `;
195
-
196
- exports[`tscTask using 'tscWatchTask' function with string value option execs expected command 1`] = `
197
- [
198
- "\${repoRoot}/node_modules/typescript/lib/tsc.js",
199
- "--module",
200
- "ESNext",
201
- "--project",
202
- "\${packageRoot}/tsconfig.json",
203
- "--watch",
204
- ]
205
- `;
@@ -1,28 +0,0 @@
1
- import * as asyncDoneAsCallback from 'async-done';
2
- import { promisify } from 'util';
3
- import type { Arguments } from 'yargs-parser';
4
- import { logger, TaskFunction, TaskContext } from 'just-task';
5
-
6
- const asyncDone = promisify(asyncDoneAsCallback);
7
-
8
- /**
9
- * Wrapper to call task function for the test.
10
- */
11
- function wrapTaskFunction(fn: TaskFunction, argv?: Arguments) {
12
- const argvOurs = argv || { _: [], $0: '' };
13
- const context: TaskContext = {
14
- argv: argvOurs,
15
- logger,
16
- };
17
- const taskRet = (fn as any).call(context, (_err: any) => undefined);
18
- return taskRet;
19
- }
20
-
21
- /**
22
- * Call the task the way real code does.
23
- */
24
- export function callTaskForTest(fn: TaskFunction, argv?: Arguments) {
25
- return asyncDone(() => {
26
- return wrapTaskFunction(fn, argv);
27
- });
28
- }
@@ -1,29 +0,0 @@
1
- /**
2
- * Mock factory for the `just-scripts-utils/lib/exec` module. We don't want to really exec or spawn anything,
3
- * but we do want the rest of the exports to work.
4
- */
5
- export function mockExecFactory() {
6
- const originalModule = jest.requireActual('just-scripts-utils/lib/exec');
7
- return {
8
- // Use real implementation of exports except for `exec` and `spawn`
9
- ...originalModule,
10
- encodeArgs: jest
11
- .fn((cmdArgs: string[]) => {
12
- // Spy on encodeArgs, but keep its original implementation
13
- return originalModule.encodeArgs(cmdArgs);
14
- })
15
- .mockName('encodeArgs'),
16
- exec: jest
17
- .fn(() => {
18
- // Don't exec in real life
19
- return Promise.resolve();
20
- })
21
- .mockName('exec'),
22
- spawn: jest
23
- .fn(() => {
24
- // Don't spawn in real life
25
- return Promise.resolve();
26
- })
27
- .mockName('spawn'),
28
- };
29
- }
@@ -1,30 +0,0 @@
1
- import { resolve } from 'path';
2
-
3
- /**
4
- * Normalizes paths in cmd args so test comparisons work no matter the machine it runs on.
5
- */
6
- export function normalizeCmdArgsForTest(cmdArgs: string[]) {
7
- const packageRootDir = process.cwd();
8
- const repoRootDir = resolve(packageRootDir, '../..');
9
- const nodePath = process.execPath;
10
-
11
- if (!cmdArgs) {
12
- return cmdArgs;
13
- }
14
-
15
- return cmdArgs.map(arg => {
16
- let newArg = undefined;
17
- if (arg.indexOf(nodePath) >= 0) {
18
- newArg = arg.replace(nodePath, '${nodeExePath}');
19
- } else if (arg.indexOf(packageRootDir) >= 0) {
20
- newArg = arg.replace(packageRootDir, '${packageRoot}');
21
- } else if (arg.indexOf(repoRootDir) >= 0) {
22
- newArg = arg.replace(repoRootDir, '${repoRoot}');
23
- }
24
- if (newArg) {
25
- // Convert backslashes to forward slashes
26
- return newArg.replace(/\\/g, '/');
27
- }
28
- return arg;
29
- });
30
- }