Skip to content

Commit

Permalink
configure jest suite to test esm
Browse files Browse the repository at this point in the history
  • Loading branch information
davidkhala committed Jan 11, 2024
1 parent e65c1d8 commit e84a058
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 12 deletions.
2 changes: 2 additions & 0 deletions __tests__/esm.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import '../dist/index.js'
it("ok", ()=>{})
8 changes: 4 additions & 4 deletions __tests__/index.ts
Original file line number Diff line number Diff line change
@@ -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')
});

});
5 changes: 4 additions & 1 deletion dist/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
export {};
export default class Index {
constructor();
}
export declare const type = "typescript";
//# sourceMappingURL=index.d.ts.map
2 changes: 1 addition & 1 deletion dist/index.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions dist/index.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
export default class Index {
constructor() {
}
}
export const type = 'typescript';
3 changes: 3 additions & 0 deletions jest.config.esm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.m?js$"
}
3 changes: 0 additions & 3 deletions jest.config.js

This file was deleted.

4 changes: 4 additions & 0 deletions jest.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"preset": "ts-jest",
"resolver": "jest-ts-webcompat-resolver"
}
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

0 comments on commit e84a058

Please sign in to comment.