Skip to content

Commit 6be68f0

Browse files
committed
fix: unit tests on Windows
1 parent 039a304 commit 6be68f0

File tree

3 files changed

+26
-14
lines changed

3 files changed

+26
-14
lines changed

packages/qwik/src/cli/add/update-files.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import fs from 'node:fs';
2-
import { extname, join } from 'node:path';
2+
import { extname, join, normalize } from 'node:path';
33
import type { FsUpdates, UpdateAppOptions } from '../types';
44
import { getPackageManager } from '../utils/utils';
55

@@ -22,12 +22,18 @@ export async function mergeIntegrationDir(
2222
const s = await fs.promises.stat(srcChildPath);
2323

2424
if (s.isDirectory()) {
25-
await mergeIntegrationDir(fileUpdates, opts, srcChildPath, destRootPath, alwaysInRoot);
25+
await mergeIntegrationDir(
26+
fileUpdates,
27+
opts,
28+
srcChildPath,
29+
normalize(destRootPath).replace(/\\/g, '/'),
30+
alwaysInRoot
31+
);
2632
} else if (s.isFile()) {
2733
const finalDestPath = getFinalDestPath(opts, destRootPath, destDir, destName, alwaysInRoot);
2834

2935
if (destName === 'package.json') {
30-
await mergePackageJsons(fileUpdates, srcChildPath, destRootPath);
36+
await mergePackageJsons(fileUpdates, srcChildPath, destRootPath.replace(/\\/g, '/'));
3137
} else if (destName === 'settings.json') {
3238
await mergeJsons(fileUpdates, srcChildPath, finalDestPath);
3339
} else if (destName === 'README.md') {
@@ -37,7 +43,7 @@ export async function mergeIntegrationDir(
3743
destName === '.prettierignore' ||
3844
destName === '.eslintignore'
3945
) {
40-
await mergeIgnoresFile(fileUpdates, srcChildPath, destRootPath);
46+
await mergeIgnoresFile(fileUpdates, srcChildPath, destRootPath.replace(/\\/g, '/'));
4147
} else if (ext === '.css') {
4248
await mergeCss(fileUpdates, srcChildPath, finalDestPath, opts);
4349
} else if (fs.existsSync(finalDestPath)) {
@@ -79,7 +85,8 @@ function getFinalDestPath(
7985
? destRootPath
8086
: destChildPath;
8187

82-
return finalDestPath;
88+
// Normalize path separators to forward slashes for cross-platform compatibility
89+
return normalize(finalDestPath).replace(/\\/g, '/');
8390
}
8491

8592
async function mergePackageJsons(fileUpdates: FsUpdates, srcPath: string, destPath: string) {

packages/qwik/src/optimizer/src/plugins/plugin.unit.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import path, { resolve } from 'node:path';
22
import { assert, describe, expect, test } from 'vitest';
3+
import { normalizePath } from '../../../testing/util';
34
import type { QwikManifest } from '../types';
45
import { ExperimentalFeatures, createQwikPlugin } from './plugin';
5-
import { normalizePath } from '../../../testing/util';
66
import { qwikVite } from './vite';
7+
import type { ResolvedId } from 'rollup';
78

89
const cwd = process.cwd();
910

@@ -244,18 +245,22 @@ describe('resolveId', () => {
244245
).toHaveProperty('id', '/root/src/routes/layout.tsx_s_7xk04rim0vu.js');
245246
expect(await plugin.resolveId(null!, './foo', '/root/src/routes/layout.tsx')).toBeFalsy();
246247
expect(
247-
await plugin.resolveId(
248-
ctx,
249-
'./layout.tsx_layout_component_usetask_1_7xk04rim0vu.js',
250-
'/root/src/routes/layout.tsx'
251-
)
252-
).toHaveProperty('id', '/root/src/routes/layout.tsx_layout_component_usetask_1_7xk04rim0vu.js');
248+
(
249+
(await plugin.resolveId(
250+
ctx,
251+
'./layout.tsx_layout_component_usetask_1_7xk04rim0vu.js',
252+
'/root/src/routes/layout.tsx'
253+
)) as ResolvedId
254+
).id
255+
).toContain('/root/src/routes/layout.tsx_layout_component_usetask_1_7xk04rim0vu.js');
253256
// this uses the already populated id we created above
254257
expect(
255258
await plugin.resolveId(
256259
{
257260
resolve: (id: string, importer: string) => {
258-
expect(id).toBe('/root/src/routes/foo');
261+
expect(id).toContain(
262+
process.platform === 'win32' ? '\\root\\src\\routes\\foo' : '/root/src/routes/foo'
263+
);
259264
expect(importer).toBe('Yey');
260265
return { id: 'hi' };
261266
},

packages/qwik/src/optimizer/src/plugins/rollup.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ export function normalizeRollupOutputOptionsObject(
190190
const sanitized = relativePath
191191
.replace(/^(\.\.\/)+/, '')
192192
.replace(/^\/+/, '')
193-
.replace(/\//g, '-');
193+
.replace(/[\\/]/g, '-');
194194
return `build/${sanitized}.js`;
195195
};
196196
}

0 commit comments

Comments
 (0)