fix(tests): windows pathing (#45799)

* fix: tests on Windows

* fix: use path join instead
pull/45804/head
Sem Bauke 2022-04-28 23:04:16 +02:00 committed by GitHub
parent 6d2b211921
commit d92eb803da
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 8 deletions

View File

@ -24,7 +24,7 @@ describe('getProjectPath helper', () => {
describe('getProjectName helper', () => {
it('should return the last path segment of the calling dir', () => {
const mockCallingDir = 'calling/dir';
const expected = `dir`;
const expected = 'dir';
// Add mock to test condition
process.env.CALLING_DIR = mockCallingDir;

View File

@ -1,9 +1,7 @@
import path from 'path';
export function getProjectPath(): string {
return (process.env.CALLING_DIR || process.cwd()) + path.sep;
return (process.env.CALLING_DIR || process.cwd()) + '/';
}
export function getProjectName(): string {
return getProjectPath().split(path.sep).slice(-2)[0];
return getProjectPath().split('/').slice(-2)[0];
}

View File

@ -69,12 +69,18 @@ describe('getMetaData helper', () => {
it('should throw if file is not found', () => {
process.env.CALLING_DIR =
'curriculum/challenges/english/superblock/mick-priject';
const errorPath = path.join(
'curriculum',
'challenges',
'_meta',
'mick-priject',
'meta.json'
);
expect(() => {
getMetaData();
}).toThrowError(
new Error(
`ENOENT: no such file or directory, open 'curriculum/challenges/_meta/mick-priject/meta.json'`
)
new Error(`ENOENT: no such file or directory, open '${errorPath}'`)
);
});