Skip to content

Commit 8fa78b2

Browse files
committed
Extension testing
1 parent 3df780f commit 8fa78b2

File tree

5 files changed

+31
-3
lines changed

5 files changed

+31
-3
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
}
1212
},
1313
"scripts": {
14-
"build": "rm -rf dist typings && npm run format && npm test && tsc && node dist/index.js",
14+
"build": "rm -rf dist typings && npm run format && npm test && tsc",
1515
"format": "prettier --write .",
1616
"docs": "rm -rf docs && npm run format && npm test && typedoc",
1717
"buildWithDocs": "rm -rf docs && npm run build && typedoc",

src/__tests__/imports.test.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { readdirSync, readFileSync } from "fs";
2+
3+
const isTsFile = (path: string) => path.endsWith(".ts");
4+
const isSourceFile = (path: string) => isTsFile(path) && !path.endsWith(".test.ts") && !path.includes("__tests__/");
5+
6+
function allSourceFilesInDir(path: string) {
7+
const files = readdirSync(path).map((filename) => `${path}/${filename}`);
8+
files.filter((filename) => !isTsFile(filename)).forEach((filename) => files.push(...allSourceFilesInDir(filename)));
9+
10+
return files.filter((filename) => isSourceFile(filename));
11+
}
12+
13+
it("should include a .js file extension in all source files", () => {
14+
allSourceFilesInDir("src").forEach((filename) => {
15+
const content = readFileSync(filename).toString();
16+
const importStatements = content.split("\r\n").filter((line) => line.match(/^import (\{ )?[\w, ]+( \})? from ".+";$/));
17+
18+
const allHaveExtension = importStatements.every((line) => {
19+
if (line.endsWith('.js";')) return true;
20+
21+
console.log(line);
22+
return false;
23+
});
24+
25+
expect(allHaveExtension).toBe(true);
26+
});
27+
});

src/defaultOptions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import FloatToolkit from ".";
1+
import FloatToolkit from "./index.js";
22

33
/**
44
* @internal

src/precisionRange.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import FloatToolkit from ".";
1+
import FloatToolkit from "./index.js";
22

33
/**
44
* @internal

tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"module": "esnext",
1010
"rootDir": "./src/",
1111
"moduleResolution": "node",
12+
"types": [],
1213
"resolveJsonModule": true,
1314

1415
"declaration": true,

0 commit comments

Comments
 (0)