From a18e0d9b68483b5eeea765e29b3bda0441ba8ada Mon Sep 17 00:00:00 2001 From: "Lin, Hung-Shin" Date: Fri, 15 Dec 2023 12:52:00 +0800 Subject: [PATCH] fix: setup Jest with TS --- jest.config.js | 4 +++- packages/file-graph/tests/file.test.ts | 2 +- packages/utils/package.json | 12 ++++++++---- packages/utils/{ => src}/auth.js | 0 packages/utils/{ => src}/commands.js | 0 packages/utils/{ => src}/dag.js | 0 packages/utils/{ => src}/index.js | 0 .../utils/{auth.test.js => tests/auth.test.ts} | 2 +- .../{commands.test.js => tests/commands.test.ts} | 2 +- packages/utils/{dag.test.js => tests/dag.test.ts} | 2 +- packages/utils/tsconfig.json | 15 +++++++++++++++ tsconfig.json | 15 +++++++++++++++ 12 files changed, 45 insertions(+), 9 deletions(-) rename packages/utils/{ => src}/auth.js (100%) rename packages/utils/{ => src}/commands.js (100%) rename packages/utils/{ => src}/dag.js (100%) rename packages/utils/{ => src}/index.js (100%) rename packages/utils/{auth.test.js => tests/auth.test.ts} (93%) rename packages/utils/{commands.test.js => tests/commands.test.ts} (95%) rename packages/utils/{dag.test.js => tests/dag.test.ts} (99%) create mode 100644 packages/utils/tsconfig.json create mode 100644 tsconfig.json diff --git a/jest.config.js b/jest.config.js index 8bb3720..0492673 100644 --- a/jest.config.js +++ b/jest.config.js @@ -1,5 +1,7 @@ /** @type {import('ts-jest').JestConfigWithTsJest} */ +// const { jsWithTs: tsjPreset } = require('ts-jest/presets') + module.exports = { - preset: 'ts-jest', + preset: 'ts-jest/presets/js-with-ts', testEnvironment: 'node', } diff --git a/packages/file-graph/tests/file.test.ts b/packages/file-graph/tests/file.test.ts index c86291e..0524f93 100644 --- a/packages/file-graph/tests/file.test.ts +++ b/packages/file-graph/tests/file.test.ts @@ -1,7 +1,7 @@ import File from '../src/file' describe('File', () => { - let file + let file: File beforeEach(() => { file = new File({ path: '/home/user', type: 'folder', discovered: true }) }) diff --git a/packages/utils/package.json b/packages/utils/package.json index 09e9205..d329e9b 100644 --- a/packages/utils/package.json +++ b/packages/utils/package.json @@ -1,8 +1,12 @@ { "name": "@linux-odyssey/utils", "version": "1.0.0", - "main": "index.js", - "type": "module", - "exports": "./index.js", - "license": "MIT" + "main": "dist/index.js", + "type": "commonjs", + "exports": "./dist/index.js", + "types": "./dist/index.d.ts", + "license": "MIT", + "scripts": { + "build": "tsc" + } } diff --git a/packages/utils/auth.js b/packages/utils/src/auth.js similarity index 100% rename from packages/utils/auth.js rename to packages/utils/src/auth.js diff --git a/packages/utils/commands.js b/packages/utils/src/commands.js similarity index 100% rename from packages/utils/commands.js rename to packages/utils/src/commands.js diff --git a/packages/utils/dag.js b/packages/utils/src/dag.js similarity index 100% rename from packages/utils/dag.js rename to packages/utils/src/dag.js diff --git a/packages/utils/index.js b/packages/utils/src/index.js similarity index 100% rename from packages/utils/index.js rename to packages/utils/src/index.js diff --git a/packages/utils/auth.test.js b/packages/utils/tests/auth.test.ts similarity index 93% rename from packages/utils/auth.test.js rename to packages/utils/tests/auth.test.ts index e7d45a7..8d617a9 100644 --- a/packages/utils/auth.test.js +++ b/packages/utils/tests/auth.test.ts @@ -1,4 +1,4 @@ -import { isValidEmail, isValidUsername } from './auth.js' +import { isValidEmail, isValidUsername } from '../src/auth' test('check valid username', () => { const valid = ['alex', 'alex123', 'john_doe', 'john-doe', 'rudeus'] diff --git a/packages/utils/commands.test.js b/packages/utils/tests/commands.test.ts similarity index 95% rename from packages/utils/commands.test.js rename to packages/utils/tests/commands.test.ts index d5392ac..9ac76ff 100644 --- a/packages/utils/commands.test.js +++ b/packages/utils/tests/commands.test.ts @@ -1,4 +1,4 @@ -import { buildFileCheckCmd } from './commands.js' +import { buildFileCheckCmd } from '../src/commands' describe('buildFileCheckCmd function', () => { it('builds the file check command correctly', () => { diff --git a/packages/utils/dag.test.js b/packages/utils/tests/dag.test.ts similarity index 99% rename from packages/utils/dag.test.js rename to packages/utils/tests/dag.test.ts index e296782..0f4201c 100644 --- a/packages/utils/dag.test.js +++ b/packages/utils/tests/dag.test.ts @@ -1,4 +1,4 @@ -import DAG from './dag.js' +import DAG from '../src/dag' describe('dag layers', () => { it('two layer', () => { diff --git a/packages/utils/tsconfig.json b/packages/utils/tsconfig.json new file mode 100644 index 0000000..76ff63c --- /dev/null +++ b/packages/utils/tsconfig.json @@ -0,0 +1,15 @@ +{ + "compilerOptions": { + "target": "ES2020", + "module": "CommonJS", + "moduleResolution": "node", + "strict": true, + "esModuleInterop": true, + "outDir": "./dist", + "declaration": true, + "sourceMap": true, + "allowJs": true + }, + "include": ["src"], + "exclude": ["node_modules", "dist"] +} diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..76ff63c --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,15 @@ +{ + "compilerOptions": { + "target": "ES2020", + "module": "CommonJS", + "moduleResolution": "node", + "strict": true, + "esModuleInterop": true, + "outDir": "./dist", + "declaration": true, + "sourceMap": true, + "allowJs": true + }, + "include": ["src"], + "exclude": ["node_modules", "dist"] +}