Skip to content

Convert to ESM #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
- uses: actions/setup-python@v5
with:
# python-version: '3.12'
cache: 'pip'
- uses: pre-commit/action@v3.0.1

Expand All @@ -23,7 +24,7 @@ jobs:

strategy:
matrix:
node-version: [18.x, 20.x]
node-version: [20.x, 22.x]

steps:
- uses: actions/checkout@v4
Expand All @@ -38,3 +39,5 @@ jobs:
- run: npm run format
- run: npm run build:debug
- run: npm run build:prod
- run: npm run check:esmloads
- run: npm run check:cjsloads
7 changes: 7 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
*
!dist/**
!src/**
!package*json
!README*
!tsconfig*
tsconfig.eslint.json
16 changes: 8 additions & 8 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ repos: #The order matters, we want prospector to run after all the sorting was d
- id: check-json
# JSON that are not json
# (?x) means verbose (we can add spaces for better readibility, but they are ignored)
exclude: (?x) ^(tsconfig(\.\w+)? | \.vscode/.*) \.json$
exclude: (?x) /?(tsconfig(\.\w+)? | \.vscode/.*) \.json$
- id: check-merge-conflict
- id: check-symlinks
- id: check-toml
Expand All @@ -19,10 +19,10 @@ repos: #The order matters, we want prospector to run after all the sorting was d
# File normalization
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/pre-commit/mirrors-prettier
rev: 'v3.1.0'
hooks:
- id: prettier
additional_dependencies:
- prettier@3.2.5
- prettier-plugin-jsdoc@1.3.0
# - repo: https://github.com/pre-commit/mirrors-prettier
# rev: 'v3.1.0'
# hooks:
# - id: prettier
# additional_dependencies:
# - prettier@3.2.5
# - prettier-plugin-jsdoc@1.3.0
4 changes: 3 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
},
"editor.formatOnSaveMode": "modificationsIfAvailable",
"[javascript,typescript,jsonc,json]": {
"editor.indentSize": "tabSize",
"editor.tabSize": 2,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSaveMode": "modificationsIfAvailable",
},
"eslint.experimental.useFlatConfig": true,
"eslint.useFlatConfig": true,
"jest.jestCommandLine": "npm test -- ",
"jest.runMode": {
"type": "on-demand",
Expand Down
2 changes: 1 addition & 1 deletion __tests__/replace.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import fc, { Arbitrary } from 'fast-check';
import { replace } from '../src';
import { replace } from '../src/replacer.js';

const EachSimpleType = [
['string', fc.string()],
Expand Down
21 changes: 21 additions & 0 deletions __tests__/server.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { serverFactory } from '@/server.js';
import type { Server } from 'http';
import request from 'supertest';
if (process.env.liveUrl) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
//@ts-ignore this enables connection to a live server and verify the app
request = request.bind(request, process.env.liveUrl);
}

let app: Server;

beforeAll(() => {
app = serverFactory();
});

describe('Server responds', () => {
// eslint-disable-next-line jest/expect-expect
test('Responds 200', async () => {
await request(app).get('/health').expect(200);
});
});
19 changes: 19 additions & 0 deletions __tests__/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Typescript config for tests
{
"extends": "../tsconfig.json",
"compilerOptions": {
"rootDir": "../",
"types": ["jest", "node"],
"composite": true,
"allowJs": true,
"sourceMap": true,
},
"references": [{ "path": "../src/" }],
"include": [
"./**/*",
"./*",
"../jest*.ts",
"../tsconfig.aliases.json",
"../package.json",
],
}
2 changes: 1 addition & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export default [
project: [
'./tsconfig.eslint.json',
'./tsconfig.json',
'./tsconfig.prod.json',
'./tsconfig.node.json',
],
},
},
Expand Down
36 changes: 32 additions & 4 deletions jest.config.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,43 @@
import type { JestConfigWithTsJest } from 'ts-jest';
import {
createDefaultEsmPreset,
pathsToModuleNameMapper,
type JestConfigWithTsJest,
} from 'ts-jest';

import { compilerOptions } from './tsconfig.aliases.json';
import packageJson from './package.json';

const pathAliases = {
...compilerOptions.paths,
// Jest wants to know the folder to do the transformation, not the `src/index.js`. 🤷
[packageJson.name]: ['src'],
};

// See here for more info https://kulshekhar.github.io/ts-jest/docs/getting-started/presets/#advanced
const preset = createDefaultEsmPreset({
tsconfig: './__tests__/tsconfig.json',
});

const config: JestConfigWithTsJest = {
preset: 'ts-jest',
...preset,
roots: ['<rootDir>'],
modulePaths: [compilerOptions.baseUrl],
moduleNameMapper: pathsToModuleNameMapper(pathAliases, {
useESM: true,
}),
modulePathIgnorePatterns: ['<rootDir>/dist/', '<rootDir>/build/'],
testRegex: [
'/tests/.*tests?.[jt]sx?',
'/__tests__/.*tests?.[jt]sx?',
'.*.(spec|test).[jt]sx?',
],
// I dono't think we need to run the spec multiple times.. the functional test on tests/ maybe.
// We can change this if we consider it useful to run the spec tests when the code is transpiled to javascript
testPathIgnorePatterns: ['node_modules', 'build/'],
// We can change this back if we consider it useful to run the spec tests when the code is transpiled to javascript
testPathIgnorePatterns: [
'node_modules',
'<rootDir>/build/',
'<rootDir>/dist/',
],
testEnvironment: 'node',
collectCoverageFrom: ['src/**/*.{js,ts,jsx,tsx}'],
verbose: true,
Expand Down
Loading
Loading