diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..7bbd3ee --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,35 @@ +name: Test + +on: + pull_request: + branches: [ main ] + push: + branches: [ main ] + +jobs: + test: + runs-on: ubuntu-latest + strategy: + matrix: + node-version: [14.x, 16.x, 18.x] + + steps: + - uses: actions/checkout@v3 + + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node-version }} + cache: 'npm' + + - name: Install dependencies + run: npm ci + + - name: Run tests + run: npm test + + - name: Upload coverage + uses: actions/upload-artifact@v3 + with: + name: coverage-${{ matrix.node-version }} + path: coverage/ diff --git a/jest.config.js b/jest.config.js new file mode 100644 index 0000000..e492b83 --- /dev/null +++ b/jest.config.js @@ -0,0 +1,30 @@ +/** @type {import('ts-jest').JestConfigWithTsJest} */ +export default { + preset: 'ts-jest', + testEnvironment: 'node', + roots: ['/src'], + testMatch: ['**/__tests__/**/*.test.ts'], + moduleFileExtensions: ['ts', 'js', 'json', 'node'], + setupFilesAfterEnv: ['/src/__tests__/setup.ts'], + transform: { + '^.+\\.tsx?$': [ + 'ts-jest', + { + useESM: true, + isolatedModules: true + } + ] + }, + moduleNameMapper: { + '^(\\.{1,2}/.*)\\.js$': '$1' + }, + extensionsToTreatAsEsm: ['.ts'], + collectCoverage: true, + coverageDirectory: 'coverage', + coverageReporters: ['text', 'lcov'], + collectCoverageFrom: [ + 'src/**/*.ts', + '!src/**/*.test.ts', + '!src/__tests__/**' + ] +}; diff --git a/package.json b/package.json index c7fc85e..346374d 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,9 @@ "scripts": { "build": "tsc && chmod +x dist/index.js", "start": "node dist/index.js", + "test": "jest --coverage", + "test:watch": "jest --watch", + "test:coverage": "jest --coverage", "test:list": "node --loader ts-node/esm src/index.ts list", "test:install": "node --loader ts-node/esm src/index.ts install", "test:installed": "node --loader ts-node/esm src/index.ts installed", @@ -16,8 +19,6 @@ "version:major": "npm version major", "publish:npm": "npm run build && npm publish --access public", "pr-check": "node src/scripts/pr-check.js", - "test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --config jest.config.mjs --watch", - "test:coverage": "NODE_OPTIONS=--experimental-vm-modules jest --config jest.config.mjs --coverage", "prepare": "npm run build" }, "bin": { diff --git a/tsconfig.json b/tsconfig.json index a7552e9..d82c280 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,7 +1,7 @@ { "compilerOptions": { "target": "ES2020", - "module": "ES2020", + "module": "commonjs", "moduleResolution": "node", "esModuleInterop": true, "strict": true,