-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathloader.test.ts
46 lines (40 loc) · 1.22 KB
/
loader.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
jest.mock("@jspm/import-map", () => ({
ImportMap: jest.fn(() => ({
resolve: jest.fn(),
})),
}));
jest.mock("../utils", () => {
const actual = jest.requireActual("../utils");
return {
__esModule: true,
...actual,
ensureDirSync: jest.fn(),
};
});
import * as utils from "../utils";
jest.mock("../parser");
jest.mock("../config", () => {
const actual = jest.requireActual("../config");
return {
__esModule: true,
...actual,
cache: '',
}
});
import { resolve } from "../loader";
const nextResolve = jest.fn();
const specifier = "specifier";
describe('loader', () => {
afterEach(() => {
jest.clearAllMocks();
})
test("resolved with basic config", async () => {
const resolveModulePathSpy = jest.spyOn(utils, 'resolveModulePath').mockReturnValue('modulePath');
const checkIfNodeOrFileProtocolSpy = jest.spyOn(utils, 'checkIfNodeOrFileProtocol').mockReturnValue(true);
const context = { parentURL: "parentURL" };
await resolve(specifier, context, nextResolve);
expect(resolveModulePathSpy).toHaveBeenCalledWith(specifier, context.parentURL);
expect(checkIfNodeOrFileProtocolSpy).toHaveBeenCalled();
expect(nextResolve).toHaveBeenCalledWith('specifier');
});
});