Skip to content

Commit 72389e3

Browse files
committed
feat: new tests + some chomp 🔥
1 parent 21fd0b1 commit 72389e3

File tree

3 files changed

+27
-7
lines changed

3 files changed

+27
-7
lines changed

chompfile.toml

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,14 @@ version = 0.1
33
[[task]]
44
name = 'build'
55
run = 'tsup src/loader.ts --format esm,cjs --dts'
6-
deps = 'npm:install'
6+
dep = 'src/loader.ts'
7+
target = 'dist/loader.js'
8+
9+
[[task]]
10+
name = 'npm:install'
11+
run = 'npm install'
12+
dep = 'package.json'
13+
target = 'package-lock.json'
714

815
[[task]]
916
name = 'clean'
@@ -21,14 +28,10 @@ run = 'commitlint --edit $1'
2128
name = 'default'
2229
run = 'npm install --no-save [email protected] @teleporthq/[email protected] @teleporthq/[email protected] chalk express morgan [email protected] [email protected] && node tests/e2e/test.js'
2330

24-
[[task]]
25-
name = 'npm:install'
26-
run = 'npm install'
27-
deps = ['package.json']
28-
2931
[[task]]
3032
name = 'lint'
3133
run = 'eslint src --ext .ts'
34+
deps = ['src/#.ts', 'tests/loader.test.ts']
3235

3336
[[task]]
3437
name = 'lint-fix'
@@ -37,6 +40,9 @@ run = 'chomp lint --fix'
3740
[[task]]
3841
name = 'pre-commit'
3942
run = 'lint-staged'
43+
deps = ['src/#.ts', 'tests/loader.test.ts']
44+
45+
[[task]]
4046

4147
[[task]]
4248
name = 'prepare'
@@ -77,3 +83,4 @@ run = 'vitest run'
7783
[[task]]
7884
name = 'typecheck'
7985
run = 'tsc --noEmit'
86+
deps = ['src/#.ts']

src/loader.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const cacheMap = new Map();
1313
* @description a convenience function to ensure a file exists
1414
* @param path
1515
*/
16-
function ensureFileSync(path: string) {
16+
export function ensureFileSync(path: string) {
1717
try {
1818
accessSync(path);
1919
} catch (err) {

tests/loader.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import * as global from "node:fs";
2+
import { join } from "node:path";
13
import { vi, test, expect } from 'vitest'
24
import { ImportMap } from "@jspm/import-map";
35

@@ -9,6 +11,8 @@ import {
911
getLastPart,
1012
getPackageNameVersionFromUrl,
1113
getVersion,
14+
parseModule,
15+
ensureFileSync,
1216
} from "../src/loader"
1317

1418
vi.mock('url', () => ({
@@ -74,3 +78,12 @@ test('getPackageNameVersionFromUrl', () => {
7478
version: '1.10.0',
7579
});
7680
});
81+
82+
83+
test('should return the specifier if the module path is a node or file protocol', async () => {
84+
const specifier = 'my-module';
85+
const modulePath1 = 'node:fs';
86+
const modulePath2 = 'file:///path/to/my/module.js';
87+
expect(await parseModule(specifier, modulePath1)).toEqual(specifier);
88+
expect(await parseModule(specifier, modulePath2)).toEqual(specifier);
89+
});

0 commit comments

Comments
 (0)