Skip to content

Commit b3abf95

Browse files
committed
fix: fix Windows interop issues
Closes #174
1 parent c1b5f61 commit b3abf95

File tree

5 files changed

+41
-21
lines changed

5 files changed

+41
-21
lines changed

ARCHITECTURE.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ document.
1616
<br />
1717

1818
<!-- symbiote-template-region-end -->
19+
<!-- TODO -->
1920

20-
There are as of yet no notable deviations or additions. See the linked document
21-
(above) for information on the architecture of this project.
21+
TODO: talk about DO_REAL_E2E and its effect on e2e tests
2222

2323
[1]: https://github.com/Xunnamius/symbiote/wiki/Generic-Project-Architecture
2424
[2]: https://github.com/Xunnamius/symbiote

src/discover.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -374,11 +374,12 @@ export async function discoverCommands(
374374
return (await import(maybeConfigFileURL)) as ImportedConfigurationModule;
375375
} catch (error) {
376376
if (
377-
isUnknownFileExtensionError(error) ||
377+
isUnknownFileExtensionSystemError(error) ||
378378
(isModuleNotFoundSystemError(error) &&
379379
(error.moduleName?.endsWith(maybeConfigPath) ||
380380
/* istanbul ignore next */
381-
error.url?.endsWith(maybeConfigPath)))
381+
// ? Just match url against url and avoid escape issues (#174)
382+
error.url === maybeConfigFileURL.toString()))
382383
) {
383384
loadDebug.warn(
384385
'a recoverable failure occurred while attempting to load configuration: %O',
@@ -1402,7 +1403,7 @@ function isModuleNotFoundSystemError(error: unknown): error is Error & {
14021403
/**
14031404
* Type-guard for Node's "ERR_UNKNOWN_FILE_EXTENSION" so-called `SystemError`s.
14041405
*/
1405-
function isUnknownFileExtensionError(error: unknown): error is Error & {
1406+
function isUnknownFileExtensionSystemError(error: unknown): error is Error & {
14061407
code: 'ERR_UNKNOWN_FILE_EXTENSION';
14071408
} {
14081409
return (

test/integration/integration-client.test.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,12 @@ describe("import {...} from '@black-flag/core'", () => {
7474
// ! is working at every level. Do not change --version. This feature
7575
// ! has broken between node versions more than once :(
7676
initialVirtualFiles: {
77-
'src/index.cjs': `require('@black-flag/core').configureProgram('${pathToFileURL(
78-
toPath(__dirname, '..', 'fixtures', 'one-file-index-cjs')
79-
).toString()}').then(({execute}) => execute(['--version']));`
77+
'src/index.cjs': `require('@black-flag/core').configureProgram('${toPath(
78+
__dirname,
79+
'..',
80+
'fixtures',
81+
'one-file-index-cjs'
82+
).replaceAll('\\', '\\\\')}').then(({execute}) => execute(['--version']));`
8083
}
8184
}
8285
);
@@ -96,9 +99,12 @@ describe("import {...} from '@black-flag/core'", () => {
9699
// ! is working at every level. Do not change --version. This feature
97100
// ! has broken between node versions more than once :(
98101
initialVirtualFiles: {
99-
'src/index.cjs': `require('@black-flag/core').runProgram('${pathToFileURL(
100-
toPath(__dirname, '..', 'fixtures', 'one-file-index-cjs')
101-
).toString()}', '--version');`
102+
'src/index.cjs': `require('@black-flag/core').runProgram('${toPath(
103+
__dirname,
104+
'..',
105+
'fixtures',
106+
'one-file-index-cjs'
107+
).replaceAll('\\', '\\\\')}', '--version');`
102108
}
103109
}
104110
);
@@ -302,6 +308,7 @@ console.log(require('@black-flag/core/util').isPreExecutionContext({}) === false
302308
expect(context.testResult.stdout).toInclude('--help');
303309
},
304310
{
311+
// ! In this test, we give Black Flag a file:// URL instead of a path
305312
initialVirtualFiles: {
306313
'src/index.cjs': `
307314
require('@black-flag/core/util').makeRunner({

test/integration/integration-smoke.test.ts

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ it('supports both CJS and ESM (js, mjs, cjs) configuration files in node CJS mod
6868
expect(context.testResult.stdout).toBe('first success');
6969
},
7070
{
71+
// ! In this test, we give Black Flag a file:// URL instead of a path
7172
initialVirtualFiles: {
7273
'src/index.cjs': `require('@black-flag/core').runProgram('${pathToFileURL(
7374
toPath(__dirname, '..', 'fixtures', 'several-files-cjs-esm')
@@ -95,9 +96,12 @@ if(typeof module !== 'undefined' || typeof require !== 'undefined') {
9596
throw new Error('expected ESM runtime but detected CJS');
9697
}
9798
98-
export default runProgram('${pathToFileURL(
99-
toPath(__dirname, '..', 'fixtures', 'several-files-cjs-esm')
100-
).toString()}', 'js mjs');`
99+
export default runProgram('${toPath(
100+
__dirname,
101+
'..',
102+
'fixtures',
103+
'several-files-cjs-esm'
104+
).replaceAll('\\', '\\\\')}', 'js mjs');`
101105
}
102106
}
103107
);
@@ -117,9 +121,12 @@ it('supports both CJS and ESM (js, mjs, cjs) configuration files in node CJS mod
117121
args: ['--no-warnings']
118122
},
119123
initialVirtualFiles: {
120-
'src/index.cjs': `require('@black-flag/core').runProgram('${pathToFileURL(
121-
toPath(__dirname, '..', 'fixtures', 'several-files-cjs-esm')
122-
).toString()}', 'js cjs');`
124+
'src/index.cjs': `require('@black-flag/core').runProgram('${toPath(
125+
__dirname,
126+
'..',
127+
'fixtures',
128+
'several-files-cjs-esm'
129+
).replaceAll('\\', '\\\\')}', 'js cjs');`
123130
}
124131
}
125132
);
@@ -146,9 +153,12 @@ if(typeof module !== 'undefined' || typeof require !== 'undefined') {
146153
throw new Error('expected ESM runtime but detected CJS');
147154
}
148155
149-
export default runProgram('${pathToFileURL(
150-
toPath(__dirname, '..', 'fixtures', 'several-files-cjs-esm')
151-
).toString()}', 'js mjs');`
156+
export default runProgram('${toPath(
157+
__dirname,
158+
'..',
159+
'fixtures',
160+
'several-files-cjs-esm'
161+
).replaceAll('\\', '\\\\')}', 'js mjs');`
152162
}
153163
}
154164
);

test/unit.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,9 @@ describe('::configureProgram', () => {
168168
});
169169

170170
await expect(bf.configureProgram('/does-not-exist')).rejects.toMatchObject({
171-
message: BfErrorMessage.BadConfigurationPath('/does-not-exist')
171+
// ? Windows path will look different than unix, so only expect the
172+
// ? dir bit (#174)
173+
message: expect.stringContaining('does-not-exist')
172174
});
173175

174176
// @ts-expect-error: testing bad call

0 commit comments

Comments
 (0)