@@ -1240,12 +1240,28 @@ describe('mysql2', () => {
12401240 }
12411241 } ) ;
12421242
1243- const { MySQL2Instrumentation } = await import ( '../src/index.js' ) ;
1243+ // Here we want to dynamically load the instrumentation.
1244+ // - `await import('../src')` does not work with tsconfig `moduleResolution: "node16"`
1245+ // because relative imports must use a suffix
1246+ // - `await import('../src/index.js')` does not work because when running
1247+ // the test files from "./test/", instead of from "./build/test/", there
1248+ // *isn't* a "index.js" file at that relative path.
1249+ // - `await import('../build/src/index.js')` does not work because that
1250+ // is a different module, hence mismatched `MySQL2Instrumentation` types.
1251+ // We fallback to using `require`. This is what the emitted JS used when
1252+ // tsconfig was target=ES2017,module=commonjs. It also matches the
1253+ // `require.cache` deletions above.
1254+ //
1255+ // (IMO, a better solution for a clean test of `mysql2/promise` would
1256+ // be to use out-of-process testing as provided by `runTestFixture` in
1257+ // contrib-test-utils.)
1258+ const { MySQL2Instrumentation } = require ( '../src' ) ;
12441259 instrumentation = new MySQL2Instrumentation ( ) ;
12451260 instrumentation . enable ( ) ;
12461261 instrumentation . disable ( ) ;
12471262
1248- createConnection = ( await import ( 'mysql2/promise' ) ) . createConnection ;
1263+ // createConnection = (await import('mysql2/promise')).createConnection;
1264+ createConnection = require ( 'mysql2/promise' ) . createConnection ;
12491265
12501266 if ( ! shouldTest ) {
12511267 // this.skip() workaround
0 commit comments