8000 Fix a unit test that was deleting files under the "src" folder and ca… · GitklcHub/rushstack@cddbab8 · GitHub
[go: up one dir, main page]

Skip to content

Commit cddbab8

Browse files
committed
Fix a unit test that was deleting files under the "src" folder and causing a race condition for the incremental analyzer
1 parent deda5c5 commit cddbab8

File tree

2 files changed

+171
-10
lines changed

2 files changed

+171
-10
lines changed
Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
/**
2+
* Defines configuration used by core Heft.
3+
*/
4+
{
5+
"$schema": "https://developer.microsoft.com/json-schemas/heft/heft.schema.json",
6+
7+
/**
8+
* Optionally specifies another JSON config file that this file extends from. This provides a way for standard
9+
* settings to be shared across multiple projects.
10+
*/
11+
"extends": "@rushstack/heft-node-rig/profiles/default/config/heft.json",
12+
13+
"eventActions": [
14+
// {
15+
// /**
16+
// * (Required) The kind of built-in operation that should be performed.
17+
// * The "deleteGlobs" action deletes files or folders that match the specified glob patterns.
18+
// */
19+
// "actionKind": "deleteGlobs",
20+
//
21+
// /**
22+
// * (Required) The Heft stage when this action should be performed. Note that heft.json event actions
23+
// * are scheduled after any plugin tasks have processed the event. For example, a "compile" event action
24+
// * will be performed after the TypeScript compiler has been invoked.
25+
// *
26+
// * Options: "clean", "pre-compile", "compile", "bundle", "post-build"
27+
// */
28+
// "heftEvent": "clean",
29+
//
30+
// /**
31+
// * (Required) A user-defined tag whose purpose is to allow configs to replace/delete handlers that
32+
// * were added by other configs.
33+
// */
34+
// "actionId": "my-example-action",
35+
//
36+
// /**
37+
// * (Required) Glob patterns to be deleted. The paths are resolved relative to the project folder.
38+
// * Documentation for supported glob syntaxes: https://www.npmjs.com/package/fast-glob
39+
// */
40+
// "globsToDelete": [
41+
// "dist",
42+
// "lib",
43+
// "lib-esnext",
44+
// "temp"
45+
// ]
46+
// },
47+
//
48+
// {
49+
// /**
50+
// * (Required) The kind of built-in operation that should be performed.
51+
// * The "copyFiles" action copies files that match the specified patterns.
52+
// */
53+
// "actionKind": "copyFiles",
54+
//
55+
// /**
56+
// * (Required) The Heft stage when this action should be performed. Note that heft.json event actions
57+
// * are scheduled after any plugin tasks have processed the event. For example, a "compile" event action
58+
// * will be performed after the TypeScript compiler has been invoked.
59+
// *
60+
// * Options: "pre-compile", "compile", "bundle", "post-build"
61+
// */
62+
// "heftEvent": "pre-compile",
63+
//
64+
// /**
65+
// * (Required) A user-defined tag whose purpose is to allow configs to replace/delete handlers that
66+
// * were added by other configs.
67+
// */
68+
// "actionId": "my-example-action",
69+
//
70+
// /**
71+
// * (Required) An array of copy operations to run perform during the specified Heft event.
72+
// */
73+
// "copyOperations": [
74+
// {
75+
// /**
76+
// * (Required) The base folder that files will be copied from, relative to the project root.
77+
// * Settings such as "includeGlobs" and "excludeGlobs" will be resolved relative
78+
// * to this folder.
79+
// * NOTE: Assigning "sourceFolder" does not by itself select any files to be copied.
80+
// */
81+
// "sourceFolder": "src",
82 6D4E +
//
83+
// /**
84+
// * (Required) One or more folders that files will be copied into, relative to the project root.
85+
// * If you specify more than one destination folder, Heft will read the input files only once, using
86+
// * streams to efficiently write multiple outputs.
87+
// */
88+
// "destinationFolders": ["dist/assets"],
89+
//
90+
// /**
91+
// * If specified, this option recursively scans all folders under "sourceFolder" and includes any files
92+
// * that match the specified extensions. (If "fileExtensions" and "includeGlobs" are both
93+
// * specified, their selections are added together.)
94+
// */
95+
// "fileExtensions": [".jpg", ".png"],
96+
//
97+
// /**
98+
// * A list of glob patterns that select files to be copied. The paths are resolved relative
99+
// * to "sourceFolder".
100+
// * Documentation for supported glob syntaxes: https://www.npmjs.com/package/fast-glob
101+
// */
102+
// "includeGlobs": ["assets/*.md"],
103+
//
104+
// /**
105+
// * A list of glob patterns that exclude files/folders from being copied. The paths are resolved relative
106+
// * to "sourceFolder". These exclusions eliminate items that were selected by the "includeGlobs"
107+
// * or "fileExtensions" setting.
108+
// */
109+
// "excludeGlobs": [],
110+
//
111+
// /**
112+
// * Normally, when files are selected under a child folder, a corresponding folder will be created in
113+
// * the destination folder. Specify flatten=true to discard the source path and copy all matching files
114+
// * to the same folder. If two files have the same name an error will be reported.
115+
// * The default value is false.
116+
// */
117+
// "flatten": false,
118+
//
119+
// /**
120+
// * If true, filesystem hard links will be created instead of copying the file. Depending on the
121+
// * operating system, this may be faster. (But note that it may cause unexpected behavior if a tool
122+
// * modifies the link.) The default value is false.
123+
// */
124+
// "hardlink": false
125+
// }
126+
// ]
127+
// }
128+
129+
{
130+
"actionKind": "copyFiles",
131+
"heftEvent": "pre-compile",
132+
"actionId": "copy-test-assets",
133+
134+
"copyOperations": [
135+
{
136+
"sourceFolder": "src",
137+
"destinationFolders": ["lib"],
138+
"fileExtensions": [".lock"]
139+
}
140+
]
141+
}
142+
],
143+
144+
/**
145+
* The list of Heft plugins to be loaded.
146+
*/
147+
"heftPlugins": [
148+
// {
149+
// /**
150+
// * The path to the plugin package.
151+
// */
152+
// "plugin": "path/to/my-plugin",
153+
//
154+
// /**
155+
// * An optional object that provides additional settings that may be defined by the plugin.
156+
// */
157+
// // "options": { }
158+
// }
159+
]
160+
}

libraries/node-core-library/src/test/LockFile.test.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ function setLockFileGetProcessStartTime(fn: (process: number) => string | undefi
1111
(LockFile as any)._getStartTime = fn;
1212
}
1313

14+
// lib/test
15+
const libTestFolder: string = path.resolve(__dirname, '../../lib/test');
16+
1417
describe(LockFile.name, () => {
1518
afterEach(() => {
1619
setLockFileGetProcessStartTime(getProcessStartTime);
@@ -113,7 +116,7 @@ describe(LockFile.name, () => {
113116

114117
test('can acquire and close a clean lockfile', () => {
115118
// ensure test folder is clean
116-
const testFolder: string = path.join(__dirname, '1');
119+
const testFolder: string = path.join(libTestFolder, '1');
117120
FileSystem.ensureEmptyFolder(testFolder);
118121

119122
const resourceName: string = 'test';
@@ -139,7 +142,7 @@ describe(LockFile.name, () => {
139142

140143
test('cannot acquire a lock if another valid lock exists', () => {
141144
// ensure test folder is clean
142-
const testFolder: string = path.join(__dirname, '2');
145+
const testFolder: string = path.join(libTestFolder, '2');
143146
FileSystem.ensureEmptyFolder(testFolder);
144147

145148
const otherPid: number = 999999999;
@@ -169,7 +172,7 @@ describe(LockFile.name, () => {
169172
});
170173
test('cannot acquire a lock if another valid lock exists with the same start time', () => {
171174
// ensure test folder is clean
172-
const testFolder: string = path.join(__dirname, '3');
175+
const testFolder: string = path.join(libTestFolder, '3');
173176
FileSystem.ensureEmptyFolder(testFolder);
174177

175178
const otherPid: number = 1; // low pid so the other lock is before us
@@ -214,7 +217,7 @@ describe(LockFile.name, () => {
214217

215218
test('will not acquire if existing lock is there', () => {
216219
// ensure test folder is clean
217-
const testFolder: string = path.join(__dirname, '1');
220+
const testFolder: string = path.join(libTestFolder, '1');
218221
FileSystem.deleteFolder(testFolder);
219222
FileSystem.ensureFolder(testFolder);
220223

@@ -232,9 +235,8 @@ describe(LockFile.name, () => {
232235

233236
test('can acquire and close a dirty lockfile', () => {
234237
// ensure test folder is clean
235-
const testFolder: string = path.join(__dirname, '1');
236-
FileSystem.deleteFolder(testFolder);
237-
FileSystem.ensureFolder(testFolder);
238+
const testFolder: string = path.join(libTestFolder, '1');
239+
FileSystem.ensureEmptyFolder(testFolder);
238240

239241
// Create a lockfile that is still hanging around on disk,
240242
const resourceName: string = 'test';
@@ -256,9 +258,8 @@ describe(LockFile.name, () => {
256258

257259
test('can acquire and close a clean lockfile', () => {
258260
// ensure test folder is clean
259-
const testFolder: string = path.join(__dirname, '1');
260-
FileSystem.deleteFolder(testFolder);
261-
FileSystem.ensureFolder(testFolder);
261+
const testFolder: string = path.join(libTestFolder, '1');
262+
FileSystem.ensureEmptyFolder(testFolder);
262263

263264
const resourceName: string = 'test';
264265
const lockFileName: string = LockFile.getLockFilePath(testFolder, resourceName);

0 commit comments

Comments
 (0)
0