-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
delete process.versions.pnp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import module from 'node:module' | ||
|
||
async function resolve (specifier, context, next) { | ||
return next( | ||
specifier === 'pnpapi' | ||
? '../tests/local/pnp/api.js' | ||
: specifier, context) | ||
} | ||
|
||
module.register && module.register(` | ||
data:text/javascript, | ||
export ${encodeURIComponent(resolve)}`.slice(1)) | ||
|
||
process.versions.pnp = '3' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import test from 'node:test' | ||
import assert from 'node:assert/strict' | ||
import module from 'node:module' | ||
import { fileURLToPath } from 'node:url' | ||
import resolvewithplus from 'resolvewithplus' | ||
import '../local/pnp/enable.js' | ||
import esmock from 'esmock' | ||
import '../local/pnp/disable.js' | ||
import pnpapi from '../local/pnp/api.js' | ||
|
||
const resolver = (id, parent) => { | ||
const url = resolvewithplus(id, parent) | ||
return url !== null ? fileURLToPath(url) : null | ||
} | ||
|
||
test.beforeEach(() => { | ||
delete pnpapi.resolveRequest | ||
}) | ||
|
||
test('should work with pnp resolver', async (t) => { | ||
if (!module.register) | ||
return assert.ok('skip test') | ||
|
||
pnpapi.resolveRequest = t.mock.fn(resolver) | ||
|
||
const main = await esmock('../local/main.js', { | ||
'../local/mainUtil.js': { | ||
createString: () => 'test string' | ||
} | ||
}) | ||
|
||
assert.equal(typeof main, 'function') | ||
assert.strictEqual(main(), 'main string, test string') | ||
assert.equal(pnpapi.resolveRequest.mock.callCount(), 2) | ||
}) |