Skip to content

Commit 7159fcb

Browse files
committed
windows path + update tests
1 parent f4dbaca commit 7159fcb

File tree

2 files changed

+43
-20
lines changed

2 files changed

+43
-20
lines changed

packages/nextjs/src/config/turbopack/constructTurbopackConfig.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export function constructTurbopackConfig({
2828
rule: {
2929
loaders: [
3030
{
31-
loader: path.resolve(__dirname, '../loaders/valueInjectionLoader.js'),
31+
loader: path.resolve(__dirname, '..', 'loaders', 'valueInjectionLoader.js'),
3232
options: {
3333
values: {
3434
_sentryRouteManifest: JSON.stringify(routeManifest),

packages/nextjs/test/config/turbopack/constructTurbopackConfig.test.ts

Lines changed: 42 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
constructTurbopackConfig,
66
safelyAddTurbopackRule,
77
} from '../../../src/config/turbopack/constructTurbopackConfig';
8-
import type { NextConfigObject, SentryBuildOptions } from '../../../src/config/types';
8+
import type { NextConfigObject } from '../../../src/config/types';
99

1010
// Mock path.resolve to return a predictable loader path
1111
vi.mock('path', async () => {
@@ -18,25 +18,19 @@ vi.mock('path', async () => {
1818

1919
describe('constructTurbopackConfig', () => {
2020
const mockRouteManifest: RouteManifest = {
21-
routes: [
21+
dynamicRoutes: [{ path: '/users/[id]', regex: '/users/([^/]+)', paramNames: ['id'] }],
22+
staticRoutes: [
2223
{ path: '/users', regex: '/users' },
23-
{ path: '/users/[id]', regex: '/users/([^/]+)', paramNames: ['id'] },
2424
{ path: '/api/health', regex: '/api/health' },
2525
],
2626
};
2727

28-
const mockSentryOptions: SentryBuildOptions = {
29-
org: 'test-org',
30-
project: 'test-project',
31-
};
32-
3328
describe('without existing turbopack config', () => {
3429
it('should create a basic turbopack config when no manifest is provided', () => {
3530
const userNextConfig: NextConfigObject = {};
3631

3732
const result = constructTurbopackConfig({
3833
userNextConfig,
39-
userSentryOptions: mockSentryOptions,
4034
});
4135

4236
expect(result).toEqual({});
@@ -47,7 +41,6 @@ describe('constructTurbopackConfig', () => {
4741

4842
const result = constructTurbopackConfig({
4943
userNextConfig,
50-
userSentryOptions: mockSentryOptions,
5144
routeManifest: mockRouteManifest,
5245
});
5346

@@ -75,11 +68,45 @@ describe('constructTurbopackConfig', () => {
7568

7669
constructTurbopackConfig({
7770
userNextConfig,
78-
userSentryOptions: mockSentryOptions,
7971
routeManifest: mockRouteManifest,
8072
});
8173

82-
expect(pathResolveSpy).toHaveBeenCalledWith(expect.any(String), '../loaders/valueInjectionLoader.js');
74+
expect(pathResolveSpy).toHaveBeenCalledWith(expect.any(String), '..', 'loaders', 'valueInjectionLoader.js');
75+
});
76+
77+
it('should handle Windows-style paths correctly', () => {
78+
// Mock path.resolve to return a Windows-style path
79+
const windowsLoaderPath = 'C:\\my\\project\\dist\\config\\loaders\\valueInjectionLoader.js';
80+
const pathResolveSpy = vi.spyOn(path, 'resolve');
81+
pathResolveSpy.mockReturnValue(windowsLoaderPath);
82+
83+
const userNextConfig: NextConfigObject = {};
84+
85+
const result = constructTurbopackConfig({
86+
userNextConfig,
87+
routeManifest: mockRouteManifest,
88+
});
89+
90+
expect(result.rules).toBeDefined();
91+
expect(result.rules!['**/instrumentation-client.*']).toBeDefined();
92+
93+
const rule = result.rules!['**/instrumentation-client.*'];
94+
expect(rule).toHaveProperty('loaders');
95+
96+
const ruleWithLoaders = rule as { loaders: Array<{ loader: string; options: any }> };
97+
expect(ruleWithLoaders.loaders).toBeDefined();
98+
expect(ruleWithLoaders.loaders).toHaveLength(1);
99+
100+
const loader = ruleWithLoaders.loaders[0]!;
101+
expect(loader).toHaveProperty('loader');
102+
expect(loader).toHaveProperty('options');
103+
expect(loader.options).toHaveProperty('values');
104+
expect(loader.options.values).toHaveProperty('_sentryRouteManifest');
105+
expect(loader.loader).toBe(windowsLoaderPath);
106+
expect(pathResolveSpy).toHaveBeenCalledWith(expect.any(String), '..', 'loaders', 'valueInjectionLoader.js');
107+
108+
// Restore the original mock behavior
109+
pathResolveSpy.mockReturnValue('/mocked/path/to/valueInjectionLoader.js');
83110
});
84111
});
85112

@@ -98,7 +125,6 @@ describe('constructTurbopackConfig', () => {
98125

99126
const result = constructTurbopackConfig({
100127
userNextConfig,
101-
userSentryOptions: mockSentryOptions,
102128
});
103129

104130
expect(result).toEqual({
@@ -125,7 +151,6 @@ describe('constructTurbopackConfig', () => {
125151

126152
const result = constructTurbopackConfig({
127153
userNextConfig,
128-
userSentryOptions: mockSentryOptions,
129154
routeManifest: mockRouteManifest,
130155
});
131156

@@ -171,7 +196,6 @@ describe('constructTurbopackConfig', () => {
171196

172197
const result = constructTurbopackConfig({
173198
userNextConfig,
174-
userSentryOptions: mockSentryOptions,
175199
routeManifest: mockRouteManifest,
176200
});
177201

@@ -186,11 +210,10 @@ describe('constructTurbopackConfig', () => {
186210
describe('with edge cases', () => {
187211
it('should handle empty route manifest', () => {
188212
const userNextConfig: NextConfigObject = {};
189-
const emptyManifest: RouteManifest = { routes: [] };
213+
const emptyManifest: RouteManifest = { dynamicRoutes: [], staticRoutes: [] };
190214

191215
const result = constructTurbopackConfig({
192216
userNextConfig,
193-
userSentryOptions: mockSentryOptions,
194217
routeManifest: emptyManifest,
195218
});
196219

@@ -215,15 +238,15 @@ describe('constructTurbopackConfig', () => {
215238
it('should handle complex route manifest', () => {
216239
const userNextConfig: NextConfigObject = {};
217240
const complexManifest: RouteManifest = {
218-
routes: [
241+
dynamicRoutes: [
219242
{ path: '/users/[id]/posts/[postId]', regex: '/users/([^/]+)/posts/([^/]+)', paramNames: ['id', 'postId'] },
220243
{ path: '/api/[...params]', regex: '/api/(.+)', paramNames: ['params'] },
221244
],
245+
staticRoutes: [],
222246
};
223247

224248
const result = constructTurbopackConfig({
225249
userNextConfig,
226-
userSentryOptions: mockSentryOptions,
227250
routeManifest: complexManifest,
228251
});
229252

0 commit comments

Comments
 (0)