-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#34, ensure no stage 2 files refer to stage 1.
- Loading branch information
Showing
5 changed files
with
123 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
stage_2_fullset/spec-snapshot/build-checks/sourceNotInFiles.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import fs from "fs/promises"; | ||
|
||
import { | ||
ModuleSourceDirectory, | ||
pathToModule | ||
} from "#utilities/source/AsyncSpecModules.js"; | ||
|
||
import { DefaultMap } from "#utilities/source/DefaultMap.js"; | ||
import readDirsDeep from "#utilities/source/readDirsDeep.js"; | ||
import { PromiseAllParallel } from "#utilities/source/PromiseTypes.js"; | ||
|
||
const stageDir: ModuleSourceDirectory = { | ||
importMeta: import.meta, | ||
pathToDirectory: "../../.." | ||
}; | ||
|
||
const filesMap = new DefaultMap<string, Promise<string>>; | ||
|
||
async function needleFoundInFiles( | ||
relativePathToDir: string, | ||
firstPart: string, | ||
secondPart: string | ||
): Promise<string[]> | ||
{ | ||
const needle = firstPart + secondPart; | ||
const topDir = pathToModule(stageDir, relativePathToDir); | ||
|
||
let { files } = await readDirsDeep(topDir); | ||
files = files.filter(f => f.endsWith(".ts")); | ||
const results = await PromiseAllParallel(files, f => sourceInFile(f, needle)); | ||
return results.filter(Boolean); | ||
} | ||
|
||
async function sourceInFile( | ||
pathToFile: string, | ||
needle: string | ||
): Promise<string> { | ||
const contents = await filesMap.getDefault(pathToFile, async () => { | ||
return fs.readFile(pathToFile, { "encoding": "utf-8"}); | ||
}); | ||
|
||
if (contents.includes(needle)) | ||
return pathToFile; | ||
return ""; | ||
} | ||
|
||
it("stage_one doesn't appear in stage two", async () => { | ||
await expectAsync(needleFoundInFiles(".", "#stage_", "one")).toBeResolvedTo([]); | ||
}); | ||
|
||
it("stage_two/snapshot doesn't appear in stage two", async () => { | ||
await expectAsync(needleFoundInFiles("snapshot", "#stage_", "two")).toBeResolvedTo([]); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters