Skip to content

Commit dca094a

Browse files
committed
test(core): windows-portable path expectations; normalize inputStamp joins
First run of the windows CI lane caught POSIX-literal assumptions: expectations now go through upath.resolve/normalize (drive-letter anchoring) and the file:// fixture is built with pathToFileURL. collectInputFiles joins via upath so its output is separator-consistent on Windows too (byte-identical on POSIX, existing stamps stay valid).
1 parent 54ca9f3 commit dca094a

5 files changed

Lines changed: 23 additions & 11 deletions

File tree

cppjs-core/cpp.js/src/utils/inputStamp.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import fs from 'node:fs';
2+
import upath from 'upath';
23
import findFiles from './findFiles.js';
34
import { getContentHash, getFileHash } from './hash.js';
45

@@ -13,9 +14,10 @@ export function collectInputFiles(roots, exts, extraFiles = []) {
1314
cwd: root,
1415
ignore: EXCLUDED_DIRS.map((dir) => `**/${dir}/**`),
1516
}).forEach((file) => files.add(file));
16-
if (fs.existsSync(`${root}/package.json`)) files.add(`${root}/package.json`);
17+
const packageJson = upath.join(root, 'package.json');
18+
if (fs.existsSync(packageJson)) files.add(packageJson);
1719
});
18-
extraFiles.forEach((file) => files.add(file));
20+
extraFiles.forEach((file) => files.add(upath.normalize(file)));
1921
return [...files].filter((file) => fs.existsSync(file)).sort();
2022
}
2123

cppjs-core/cpp.js/test/getAbsolutePath.test.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@ describe('getAbsolutePath', () => {
1111
expect(getAbsolutePath('/some/project', undefined)).toBeNull();
1212
});
1313

14+
// upath.resolve anchors POSIX-style absolutes to the current drive on Windows,
15+
// so expectations resolve the same way instead of hardcoding the POSIX literal.
1416
test('returns the path as-is when it is already absolute', () => {
15-
expect(getAbsolutePath('/some/project', '/etc/foo')).toBe('/etc/foo');
17+
expect(getAbsolutePath('/some/project', '/etc/foo')).toBe(upath.resolve('/etc/foo'));
1618
});
1719

1820
test('joins relative path against the projectPath when projectPath is provided', () => {
19-
expect(getAbsolutePath('/some/project', 'src/native')).toBe('/some/project/src/native');
21+
expect(getAbsolutePath('/some/project', 'src/native')).toBe(upath.resolve('/some/project/src/native'));
2022
});
2123

2224
test('resolves relative path against cwd when projectPath is missing', () => {
@@ -25,6 +27,6 @@ describe('getAbsolutePath', () => {
2527
});
2628

2729
test('normalizes ../ in relative paths against the projectPath', () => {
28-
expect(getAbsolutePath('/some/project/sub', '../sibling')).toBe('/some/project/sibling');
30+
expect(getAbsolutePath('/some/project/sub', '../sibling')).toBe(upath.resolve('/some/project/sibling'));
2931
});
3032
});

cppjs-core/cpp.js/test/getParentPath.test.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
import { describe, test, expect } from 'vitest';
2+
import { pathToFileURL } from 'node:url';
3+
import upath from 'upath';
24
import getParentPath from '../src/utils/getParentPath.js';
35

46
describe('getParentPath', () => {
7+
// Built with pathToFileURL so the URL is valid on Windows too (drive letter);
8+
// a hardcoded POSIX file:// URL is rejected by fileURLToPath there.
59
test('strips the file segment from a file:// URL', () => {
6-
const input = 'file:///Users/me/project/cppjs-core/cpp.js/src/index.js';
7-
expect(getParentPath(input)).toBe('/Users/me/project/cppjs-core/cpp.js/src');
10+
const input = pathToFileURL(upath.resolve('/Users/me/project/cppjs-core/cpp.js/src/index.js')).href;
11+
expect(getParentPath(input)).toBe(upath.resolve('/Users/me/project/cppjs-core/cpp.js/src'));
812
});
913

1014
test('strips the file segment from a plain absolute path', () => {

cppjs-core/cpp.js/test/inputStamp.test.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,19 @@ import { describe, test, expect, beforeEach, afterEach } from 'vitest';
22
import fs from 'node:fs';
33
import os from 'node:os';
44
import path from 'node:path';
5+
import upath from 'upath';
56
import { collectInputFiles, computeInputStamp } from '../src/utils/inputStamp.js';
67

78
describe('inputStamp', () => {
89
let root;
910

11+
// collectInputFiles returns upath-normalized paths (glob posix output), so
12+
// expectations normalize the same way for Windows.
1013
const write = (rel, content = '') => {
1114
const file = path.join(root, rel);
1215
fs.mkdirSync(path.dirname(file), { recursive: true });
1316
fs.writeFileSync(file, content);
14-
return file;
17+
return upath.normalize(file);
1518
};
1619

1720
beforeEach(() => {

cppjs-core/cpp.js/test/loadConfig.test.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { describe, test, expect, beforeEach, afterEach } from 'vitest';
22
import fs from 'node:fs';
33
import os from 'node:os';
44
import path from 'node:path';
5+
import upath from 'upath';
56
import loadConfig, { getFilledConfig } from '../src/state/loadConfig.js';
67

78
describe('excludedDependencies', () => {
@@ -156,7 +157,7 @@ describe('dependency replacement', () => {
156157
expect(dep.general.name).toBe('gdal');
157158
expect(dep.general.alias.package).toBe('@cpp.js/package-gdal');
158159
expect(dep.export.libName).toEqual(['gdal']);
159-
expect(dep.paths.project).toBe('/new/aaagdal');
160+
expect(dep.paths.project).toBe(upath.resolve('/new/aaagdal'));
160161
});
161162

162163
test('leaves a dependency untouched when no replace entry matches', () => {
@@ -166,7 +167,7 @@ describe('dependency replacement', () => {
166167
dependencies: [{ general: { name: 'gdal' }, paths: { project: '/old/gdal' } }],
167168
};
168169
const dep = fill(app, { proj: { replace: {} } }).allDependencies[0];
169-
expect(dep.paths.project).toBe('/old/gdal');
170+
expect(dep.paths.project).toBe(upath.resolve('/old/gdal'));
170171
});
171172
});
172173

@@ -192,6 +193,6 @@ describe('raw config isolation', () => {
192193
first.paths.output = '/app/.cppjs/deps/z/dist';
193194

194195
expect(rawDep.paths.project).toBe('/pkg/zlib-wasm');
195-
expect(fill(app).allDependencies[0].paths.project).toBe('/pkg/zlib-wasm');
196+
expect(fill(app).allDependencies[0].paths.project).toBe(upath.resolve('/pkg/zlib-wasm'));
196197
});
197198
});

0 commit comments

Comments
 (0)