Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2017 from snyk/test/improve-test-helpers
test: re-use the entity generator helpers across all tests
- Loading branch information
Showing
4 changed files
with
80 additions
and
125 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
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,21 @@ | ||
import * as fs from 'fs'; | ||
import * as pathLib from 'path'; | ||
|
||
export function readFileHelper(workspacesPath: string, path: string): string { | ||
// because we write multiple time the file | ||
// may be have already been updated in fixed-* name | ||
// so try read that first | ||
const res = pathLib.parse(path); | ||
const fixedPath = pathLib.resolve( | ||
workspacesPath, | ||
res.dir, | ||
`fixed-${res.base}`, | ||
); | ||
let file; | ||
try { | ||
file = fs.readFileSync(fixedPath, 'utf-8'); | ||
} catch (e) { | ||
file = fs.readFileSync(pathLib.resolve(workspacesPath, path), 'utf-8'); | ||
} | ||
return file; | ||
} |