Skip to content

Commit

Permalink
Merge 7ac30c4 into 3a247e1
Browse files Browse the repository at this point in the history
  • Loading branch information
marcalexiei committed Feb 24, 2024
2 parents 3a247e1 + 7ac30c4 commit 7f37a65
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 44 deletions.
39 changes: 37 additions & 2 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
- name: Format check
run: npm run format

- name: Format check
- name: Lint
run: npm run lint

build:
Expand Down Expand Up @@ -56,6 +56,12 @@ jobs:
matrix:
node: [ '20.x', '18.x' ]
os: [ubuntu-latest]
# Collect coverage only for node 20 and ubuntu-latest, no need to run it twice
# @see https://docs.github.com/en/actions/using-jobs/using-a-matrix-for-your-jobs#expanding-or-adding-matrix-configurations
include:
- collectCoverage: true
node: '20.x'
os: ubuntu-latest
steps:
- uses: actions/checkout@v4

Expand All @@ -69,10 +75,39 @@ jobs:
run: npm install

- name: Test
if: ${{ !matrix.collectCoverage }}
run: npm test

- name: Run test to generate coverage
- name: Test with coverage
if: ${{ matrix.collectCoverage }}
run: npm run test:coverage

- name: Coveralls
if: ${{ matrix.collectCoverage }}
uses: coverallsapp/github-action@v2

testTypescript:
name: Test typescript@v${{ matrix.tsVersion }}
runs-on: ubuntu-latest
strategy:
matrix:
tsVersion: [ '5', '4' ]
steps:
- uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: 'npm'

- name: Install dependencies
run: npm install

- name: Install ${{ matrix.tsVersion }}
run: |
npm install typescript@${{ matrix.tsVersion }}
npm run generate_ts_v4_index
- name: Test
run: npm run test:typescript
5 changes: 2 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,9 @@ npm run test:local
### Typescript

If you want to run only a specific project use `--project` flag.
As value provide `ts-` followed by the folder name

```bash
npx vitest --project ts-custom-types
npm run test:typescript -- --project custom-types
```

#### New Test scenario
Expand All @@ -51,4 +50,4 @@ If you need to create a new typescript test scenario:
2. Create a `tsconfig.json` and a `i18next.d.ts` with the relevant properties inside `CustomOptions`
3. If you need to test multiple tsconfig within the same scenario you can create another `tsconfig.json` but with a semantic name between tsconfig and json.
E.g.: `tsconfig.nonEsModuleInterop.json` inside `test/typescript/misc`
4. For more information about workspace setup check `vitest.workspace.mts`
4. For more information about workspace setup check `vitest.workspace.typescript.mts`
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,12 @@
"format": "prettier \"{,**/}*.{ts,tsx,mts,js,json,md}\" --check",
"format:fix": "prettier \"{,**/}*.{ts,tsx,mts,js,json,md}\" --write",
"pretest": "npm run generate_ts_v4_index",
"pretest:typescript": "npm run generate_ts_v4_index",
"test": "vitest --run",
"test:coverage": "vitest --project runtime --project compatibility --coverage --run",
"test:coverage": "vitest --coverage --run",
"test:runtime": "vitest --project runtime",
"test:compatibility": "vitest --project compatibility",
"test:typescript": "vitest --workspace vitest.workspace.typescript.mts",
"test:local": "vitest --workspace vitest.workspace.local.mts",
"build": "rimraf dist && rollup -c && echo '{\"type\":\"module\"}' > dist/esm/package.json && cpy \"./dist/umd/*.js\" ./",
"generate_ts_v4_index": "cp index.d.ts index.v4.d.ts && node -e \"fs.writeFileSync('index.v4.d.ts', fs.readFileSync('index.v4.d.ts').toString().replace(/t.js/g, 't.v4.js').replace(/export type \\* /g, '// export type * '))\"",
Expand Down
38 changes: 0 additions & 38 deletions vitest.workspace.mts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { readdirSync } from 'node:fs';
// eslint-disable-next-line import/no-extraneous-dependencies
import { defineWorkspace } from 'vitest/config';
import type { UserProjectConfigExport } from 'vitest/config';

export default defineWorkspace([
{
Expand All @@ -17,40 +15,4 @@ export default defineWorkspace([
dir: './test/compatibility',
},
},

/**
* If you need to test multiple typescript configurations (like misc) simply create a file named tsconfig.{customName}.json
* and this script will automatically create a new workspace named with the dirName followed by `customName`
*/
...readdirSync('./test/typescript', { withFileTypes: true })
.filter((dir) => dir.isDirectory())
.reduce<UserProjectConfigExport[]>((workspaces, dir) => {
const dirPath = `test/typescript/${dir.name}` as const;

const tsConfigFiles = readdirSync(dirPath).filter(
// Do not include temporary vitest tsconfig files
(it) => it.startsWith('tsconfig.') && it.endsWith('.json') && !it.includes('vitest-temp'),
);

tsConfigFiles.forEach((tsConfigFileName) => {
const workspaceName =
tsConfigFileName === 'tsconfig.json'
? dir.name
: `${dir.name}-${tsConfigFileName.split('.')[1]}`;

workspaces.push({
test: {
dir: `./${dirPath}`,
name: `ts-${workspaceName}`,
typecheck: {
enabled: true,
include: [`**/${dirPath}/*.test.ts`],
tsconfig: `./${dirPath}/${tsConfigFileName}`,
},
},
});
});

return workspaces;
}, []),
]);
42 changes: 42 additions & 0 deletions vitest.workspace.typescript.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { readdirSync } from 'node:fs';
// eslint-disable-next-line import/no-extraneous-dependencies
import { defineWorkspace } from 'vitest/config';
import type { UserProjectConfigExport } from 'vitest/config';

export default defineWorkspace(
/**
* If you need to test multiple typescript configurations (like misc) simply create a file named tsconfig.{customName}.json
* and this script will automatically create a new workspace named with the dirName followed by `customName`
*/
readdirSync('./test/typescript', { withFileTypes: true })
.filter((dir) => dir.isDirectory())
.reduce<UserProjectConfigExport[]>((workspaces, dir) => {
const dirPath = `test/typescript/${dir.name}` as const;

const tsConfigFiles = readdirSync(dirPath).filter(
// Do not include temporary vitest tsconfig files
(it) => it.startsWith('tsconfig.') && it.endsWith('.json') && !it.includes('vitest-temp'),
);

tsConfigFiles.forEach((tsConfigFileName) => {
const workspaceName =
tsConfigFileName === 'tsconfig.json'
? dir.name
: `${dir.name}-${tsConfigFileName.split('.')[1]}`;

workspaces.push({
test: {
dir: `./${dirPath}`,
name: workspaceName,
typecheck: {
enabled: true,
include: [`**/${dirPath}/*.test.ts`],
tsconfig: `./${dirPath}/${tsConfigFileName}`,
},
},
});
});

return workspaces;
}, []),
);

0 comments on commit 7f37a65

Please sign in to comment.