From e84a0587035423e5fa1b8993a371773ebb6ce581 Mon Sep 17 00:00:00 2001 From: David Liu Date: Thu, 11 Jan 2024 18:59:29 +0800 Subject: [PATCH] configure jest suite to test esm --- __tests__/esm.mjs | 2 ++ __tests__/index.ts | 8 ++++---- dist/index.d.ts | 5 ++++- dist/index.d.ts.map | 2 +- dist/index.js | 7 +++++-- jest.config.esm.json | 3 +++ jest.config.js | 3 --- jest.config.json | 4 ++++ package.json | 6 +++++- 9 files changed, 28 insertions(+), 12 deletions(-) create mode 100644 __tests__/esm.mjs create mode 100644 jest.config.esm.json delete mode 100644 jest.config.js create mode 100644 jest.config.json diff --git a/__tests__/esm.mjs b/__tests__/esm.mjs new file mode 100644 index 0000000..2aa1d79 --- /dev/null +++ b/__tests__/esm.mjs @@ -0,0 +1,2 @@ +import '../dist/index.js' +it("ok", ()=>{}) \ No newline at end of file diff --git a/__tests__/index.ts b/__tests__/index.ts index 651a2e7..7b40293 100644 --- a/__tests__/index.ts +++ b/__tests__/index.ts @@ -1,10 +1,10 @@ -import Index, {type} from '../src/index'; -import * as assert from 'assert'; +import Index, { type } from '../src/index'; + describe('', () => { it('', () => { - assert.strictEqual(new Index().constructor.name, 'Index'); - assert.strictEqual(type, 'typescript'); + expect(new Index().constructor.name).toBe('Index'); + expect(type).toBe('typescript') }); }); \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts index e26a57a..06ba5b1 100644 --- a/dist/index.d.ts +++ b/dist/index.d.ts @@ -1,2 +1,5 @@ -export {}; +export default class Index { + constructor(); +} +export declare const type = "typescript"; //# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/dist/index.d.ts.map b/dist/index.d.ts.map index 535b86d..4dff9a6 100644 --- a/dist/index.d.ts.map +++ b/dist/index.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":""} \ No newline at end of file +{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,OAAO,OAAO,KAAK;;CAGzB;AACD,eAAO,MAAM,IAAI,eAAe,CAAC"} \ No newline at end of file diff --git a/dist/index.js b/dist/index.js index c8ad2e5..c712d97 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1,2 +1,5 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); +export default class Index { + constructor() { + } +} +export const type = 'typescript'; diff --git a/jest.config.esm.json b/jest.config.esm.json new file mode 100644 index 0000000..9d686ab --- /dev/null +++ b/jest.config.esm.json @@ -0,0 +1,3 @@ +{ + "testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.m?js$" +} diff --git a/jest.config.js b/jest.config.js deleted file mode 100644 index c2b45a6..0000000 --- a/jest.config.js +++ /dev/null @@ -1,3 +0,0 @@ -module.exports = { - preset: 'ts-jest', -}; \ No newline at end of file diff --git a/jest.config.json b/jest.config.json new file mode 100644 index 0000000..82b362e --- /dev/null +++ b/jest.config.json @@ -0,0 +1,4 @@ +{ + "preset": "ts-jest", + "resolver": "jest-ts-webcompat-resolver" +} \ No newline at end of file diff --git a/package.json b/package.json index 9ab89cd..cac1955 100644 --- a/package.json +++ b/package.json @@ -2,18 +2,22 @@ "scripts": { "compile": "tsc --project tsconfig.json", "test": "jest", + "test:esm": "node --experimental-vm-modules node_modules/jest/bin/jest.js --config=jest.config.esm.json", "mocha-test": "ts-mocha test/*" }, "main": "dist/index.js", "types": "dist/index.d.ts", "devDependencies": { "@types/jest": "latest", + "@types/node": "latest", "@typescript-eslint/eslint-plugin": "latest", "@typescript-eslint/parser": "latest", "eslint": "latest", "jest": "latest", + "jest-ts-webcompat-resolver": "latest", "ts-jest": "latest", "ts-mocha": "latest", "typescript": "latest" - } + }, + "type": "module" }