From e19fd0c43f1ab17a223dcf530b2d29ba79e212fc Mon Sep 17 00:00:00 2001 From: merceyz Date: Tue, 22 Aug 2023 19:59:00 +0200 Subject: [PATCH] test: add test --- .../pkg-tests-specs/sources/pnp-esm.test.ts | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/packages/acceptance-tests/pkg-tests-specs/sources/pnp-esm.test.ts b/packages/acceptance-tests/pkg-tests-specs/sources/pnp-esm.test.ts index ce4f711f0e44..89ec6c7cae34 100644 --- a/packages/acceptance-tests/pkg-tests-specs/sources/pnp-esm.test.ts +++ b/packages/acceptance-tests/pkg-tests-specs/sources/pnp-esm.test.ts @@ -1004,4 +1004,32 @@ describe(`Plug'n'Play - ESM`, () => { ), ); }); + + it( + `should use the commonjs resolver in commonjs files imported from ESM`, + makeTemporaryEnv( + { + type: `module`, + }, + async ({ path, run, source }) => { + await xfs.writeFilePromise(ppath.join(path, `foo.js`), `import './bar.cjs';`); + await xfs.writeFilePromise( + ppath.join(path, `bar.cjs`), + ` + require('module')._extensions['.custom'] = require('module')._extensions['.js']; + require('./baz'); + ` + ); + await xfs.writeFilePromise(ppath.join(path, `baz.custom`), `console.log(42);`); + + await expect(run(`install`)).resolves.toMatchObject({ code: 0 }); + + await expect(run(`node`, `./foo.js`)).resolves.toMatchObject({ + code: 0, + stdout: `42\n`, + stderr: '', + }); + } + ) + ); });