-
-
Notifications
You must be signed in to change notification settings - Fork 127
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented improved behavior of #633
- Loading branch information
1 parent
a94053a
commit be47a24
Showing
4 changed files
with
148 additions
and
13 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
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 |
---|---|---|
|
@@ -2,7 +2,13 @@ import { readImportmap } from './importmap'; | |
|
||
jest.mock('./npm', () => ({ | ||
tryResolvePackage(id, dir) { | ||
return `${dir}/${id}/index.js`; | ||
if (id === 'qxz') { | ||
return undefined; | ||
} else if (id.endsWith('package.json')) { | ||
return `${dir}/${id}`; | ||
} else { | ||
return `${dir}/${id}/index.js`; | ||
} | ||
}, | ||
})); | ||
|
||
|
@@ -15,6 +21,28 @@ const mockPackages = { | |
name: 'bar', | ||
version: '1.0.0', | ||
}, | ||
'/data/app1': { | ||
name: 'app1', | ||
version: '1.0.0', | ||
importmap: { | ||
imports: { | ||
'[email protected]': 'foo', | ||
}, | ||
}, | ||
}, | ||
'/data/app1/foo': { | ||
name: 'foo', | ||
version: '1.2.3', | ||
}, | ||
'/data/app2': { | ||
name: 'app1', | ||
version: '1.0.0', | ||
importmap: { | ||
imports: { | ||
'[email protected]': '', | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
jest.mock('./io', () => ({ | ||
|
@@ -191,4 +219,60 @@ describe('Importmap', () => { | |
), | ||
).rejects.toThrow(); | ||
}); | ||
|
||
it('fails when the explicitly shared package is not installed', async () => { | ||
await expect( | ||
readImportmap( | ||
'/data', | ||
{ | ||
importmap: { | ||
imports: { | ||
'qxz': '', | ||
}, | ||
}, | ||
}, | ||
false, | ||
), | ||
).rejects.toThrow(); | ||
}); | ||
|
||
it('accepts an importmap with valid resolvable inherited deps', async () => { | ||
const deps = await readImportmap( | ||
'/data', | ||
{ | ||
importmap: { | ||
imports: {}, | ||
inherit: ['app1'], | ||
}, | ||
}, | ||
false, | ||
); | ||
expect(deps).toEqual([ | ||
{ | ||
alias: undefined, | ||
entry: '/data/app1/foo/index.js', | ||
id: '[email protected]', | ||
isAsync: false, | ||
name: 'foo', | ||
ref: 'foo.js', | ||
requireId: '[email protected]', | ||
type: 'local', | ||
parents: ['app1'], | ||
}, | ||
]); | ||
}); | ||
|
||
it('accepts an importmap with valid but unresolvable inherited deps', async () => { | ||
const deps = await readImportmap( | ||
'/data', | ||
{ | ||
importmap: { | ||
imports: {}, | ||
inherit: ['app2'], | ||
}, | ||
}, | ||
false, | ||
); | ||
expect(deps).toEqual([]); | ||
}); | ||
}); |
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
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