Skip to content

Commit

Permalink
test: migrate mock files to TypeScript
Browse files Browse the repository at this point in the history
  • Loading branch information
JounQin committed Jan 16, 2024
1 parent 2f57f1b commit c6b53ee
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 27 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ jobs:
- name: Install Dependencies
run: yarn --immutable

- name: Build and Test
run: yarn run-s build test

- name: Lint
run: yarn lint
if: matrix.node == 18
env:
EFF_NO_LINK_RULES: true
PARSER_NO_WATCH: true

- name: Build and Test
run: yarn run-s build test

- name: Codecov
uses: codecov/codecov-action@v3
10 changes: 6 additions & 4 deletions __mocks__/execa.js → __mocks__/execa.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,18 @@ const mockStream = () => ({
const mockExeca = jest.fn().mockReturnValue({
stdout: mockStream(),
stderr: mockStream(),
// eslint-disable-next-line no-empty-function
// eslint-disable-next-line @typescript-eslint/no-empty-function
kill: () => {},
})

const mockExecaSync = jest.fn().mockReturnValue({
stdout: '',
stderr: '',
// eslint-disable-next-line no-empty-function
// eslint-disable-next-line @typescript-eslint/no-empty-function
kill: () => {},
})

module.exports = mockExeca
module.exports.sync = mockExecaSync
export = mockExeca

// @ts-expect-error -- intended
mockExeca.sync = mockExecaSync
19 changes: 0 additions & 19 deletions __mocks__/prettier.js

This file was deleted.

17 changes: 17 additions & 0 deletions __mocks__/prettier.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import path from 'path'

export = {
format: jest.fn((input: string) => 'formatted:' + input),
resolveConfig: {
sync: jest.fn((file: string) => ({ file })),
},
getFileInfo: {
sync: jest.fn((file: string) => {
const ext = path.extname(file)
if (ext === '.js' || ext === '.md') {
return { ignored: false, inferredParser: 'babel' }
}
return { ignored: false, inferredParser: null }
}),
},
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@
"prettier": "@1stg/prettier-config",
"size-limit": [
{
"path": "src/index.js",
"path": "src/index.ts",
"limit": "1KB"
}
]
Expand Down

0 comments on commit c6b53ee

Please sign in to comment.