Skip to content

Commit

Permalink
add resolver tests for mjs and cjs files
Browse files Browse the repository at this point in the history
  • Loading branch information
FogelAI committed Jul 17, 2024
1 parent fac5725 commit 29973fc
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions tests/src/resolver.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,44 @@ describe('Resolver class', () => {
expect(result).toEqual(expectedResult);
});

test('when resolving a relative path from a regular path, it should return a ResolvedPath instance where absEsmFile contains the file path with mjs extension', () => {
// Arrange
mock({
"c:\\path\\to.mjs": "",
});
const path = "./to";
const from = "c:\\path\\from.js";
const expectedResult = {
absCjsFile: "",
absEsmFile: "c:\\path\\to.mjs"
}

// Act
const result = resolver.resolve(path,from);

// Assert
expect(result).toEqual(expectedResult);
});

test('when resolving a relative path from a regular path, it should return a ResolvedPath instance where absCjsFile contains the file path with cjs extension', () => {
// Arrange
mock({
"c:\\path\\to.cjs": "",
});
const path = "./to";
const from = "c:\\path\\from.js";
const expectedResult = {
absCjsFile: "c:\\path\\to.cjs",
absEsmFile: ""
}

// Act
const result = resolver.resolve(path,from);

// Assert
expect(result).toEqual(expectedResult);
});

test('when resolving a package from a regular path, it should return a ResolvedPath instance where absEsmFile and absCjsFile include file paths of the module and main keys (if they exist) from the package.json file', () => {
// Arrange
mock({
Expand Down

0 comments on commit 29973fc

Please sign in to comment.