@@ -14,87 +14,48 @@ vi.mock(import("node:fs"), async (importOriginal) => {
1414} ) ;
1515
1616describe ( "LoadInstrumentationModule" , ( ) => {
17- test ( "patch when an instrumentation file is not present" , async ( ) => {
18- const code = `
19- export default class NextNodeServer extends BaseServer<
20- Options,
21- NodeNextRequest,
22- NodeNextResponse
23- > {
24- protected async loadInstrumentationModule() {
25- if (!this.serverOptions.dev) {
26- try {
27- this.instrumentation = await dynamicRequire(
28- resolve(
29- this.serverOptions.dir || '.',
30- this.serverOptions.conf.distDir!,
31- 'server',
32- INSTRUMENTATION_HOOK_FILENAME
33- )
34- )
35- } catch (err: any) {
36- if (err.code !== 'MODULE_NOT_FOUND') {
37- throw new Error(
38- 'An error occurred while loading the instrumentation hook',
39- { cause: err }
40- )
17+ const code = `
18+ export default class NextNodeServer extends BaseServer {
19+ protected async loadInstrumentationModule() {
20+ if (!this.serverOptions.dev) {
21+ try {
22+ this.instrumentation = await dynamicRequire(
23+ resolve(
24+ this.serverOptions.dir || '.',
25+ this.serverOptions.conf.distDir!,
26+ 'server',
27+ INSTRUMENTATION_HOOK_FILENAME
28+ )
29+ )
30+ } catch (err: any) {
31+ if (err.code !== 'MODULE_NOT_FOUND') {
32+ throw new Error(
33+ 'An error occurred while loading the instrumentation hook',
34+ { cause: err }
35+ )
36+ }
37+ }
38+ }
39+ return this.instrumentation
4140 }
4241 }
43- }
44- return this.instrumentation
45- }
46- }` ;
42+ ` ;
4743
44+ test ( "patch when an instrumentation file is not present" , async ( ) => {
4845 expect ( patchCode ( code , await getRule ( null ) ) ) . toMatchInlineSnapshot ( `
49- "export default class NextNodeServer extends BaseServer<
50- Options,
51- NodeNextRequest,
52- NodeNextResponse
53- > {
54- async loadInstrumentationModule() { this.instrumentation = null; return this.instrumentation; }
55- }"
56- ` ) ;
46+ "export default class NextNodeServer extends BaseServer {
47+ async loadInstrumentationModule() { this.instrumentation = null; return this.instrumentation; }
48+ }
49+ "
50+ ` ) ;
5751 } ) ;
5852
5953 test ( "patch when an instrumentation file is present" , async ( ) => {
60- const code = `
61- export default class NextNodeServer extends BaseServer<
62- Options,
63- NodeNextRequest,
64- NodeNextResponse
65- > {
66- protected async loadInstrumentationModule() {
67- if (!this.serverOptions.dev) {
68- try {
69- this.instrumentation = await dynamicRequire(
70- resolve(
71- this.serverOptions.dir || '.',
72- this.serverOptions.conf.distDir!,
73- 'server',
74- INSTRUMENTATION_HOOK_FILENAME
75- )
76- )
77- } catch (err: any) {
78- if (err.code !== 'MODULE_NOT_FOUND') {
79- throw new Error(
80- 'An error occurred while loading the instrumentation hook',
81- { cause: err }
82- )
83- }
84- }
85- }
86- return this.instrumentation
87- }
88- }` ;
89-
9054 expect ( patchCode ( code , await getRule ( "/_file_exists_/instrumentation.js" ) ) ) . toMatchInlineSnapshot ( `
91- "export default class NextNodeServer extends BaseServer<
92- Options,
93- NodeNextRequest,
94- NodeNextResponse
95- > {
96- async loadInstrumentationModule() { this.instrumentation = require('/_file_exists_/instrumentation.js'); return this.instrumentation; }
97- }"
98- ` ) ;
55+ "export default class NextNodeServer extends BaseServer {
56+ async loadInstrumentationModule() { this.instrumentation = require('/_file_exists_/instrumentation.js'); return this.instrumentation; }
57+ }
58+ "
59+ ` ) ;
9960 } ) ;
10061} ) ;
0 commit comments