diff --git a/README.md b/README.md index c8e0bd2b..b0375c25 100644 --- a/README.md +++ b/README.md @@ -82,7 +82,7 @@ jobs: ``` > **Warning** -> +> > This brings worse DX - you can test action only when it is merged into your main branch. **Any changes to the workflow file will be taken only after merging them to the main branch** ## Custom token @@ -147,9 +147,9 @@ with: test-script: npm test ``` -## Usage with `yarn` or `pnpm` +## Usage with `yarn` `pnpm`, or `bun` -By default, this action will install your dependencies using `npm`. If you are using `yarn` or `pnpm`, you can specify it in the `package-manager` option: +By default, this action will install your dependencies using `npm`. If you are using `yarn`, `pnpm`, or `bun`, you can specify it in the `package-manager` option: ```yml with: @@ -163,6 +163,13 @@ with: package-manager: pnpm ``` +or + +```yml +with: + package-manager: bun +``` + ## Use existing test report(s) To bypass running unit tests, you can pass the filepath to the current report.json diff --git a/action.yml b/action.yml index 89ab15ff..6898593e 100644 --- a/action.yml +++ b/action.yml @@ -29,7 +29,7 @@ inputs: default: all package-manager: required: false - description: 'Which package manager to use; can be `npm`, `yarn`, or `pnpm`' + description: 'Which package manager to use; can be `npm`, `yarn`, `pnpm`, or `bun`' default: 'npm' skip-step: required: false diff --git a/docs/src/pages/configuration.md b/docs/src/pages/configuration.md index 1a18d9e1..d85a6da6 100644 --- a/docs/src/pages/configuration.md +++ b/docs/src/pages/configuration.md @@ -98,7 +98,7 @@ If you want to enable only specific annotations, you can specify following choic ### package-manager -By default, action uses [npm](https://github.com/npm/cli#readme) package manager. But, if you want to use [yarn](https://github.com/yarnpkg/berry#readme) or [pnpm](https://pnpm.io/), simply set `package-manager`option to `yarn` or `pnpm`: +By default, action uses [npm](https://github.com/npm/cli#readme) package manager. But, if you want to use [yarn](https://github.com/yarnpkg/berry#readme), [pnpm](https://pnpm.io/), or [bun](https://bun.sh/), simply set `package-manager`option to `yarn`, `pnpm`, or `bun`: ```yaml with: @@ -114,6 +114,14 @@ with: package-manager: pnpm ``` +or + +```yaml +with: + github-token: ${{ secrets.GITHUB_TOKEN }} + package-manager: bun +``` + ### skip-step If you've installed dependencies in previous step, or you already have `report.json` file, you can skip `install` or `all` steps. For instance: diff --git a/docs/src/pages/quick-start.md b/docs/src/pages/quick-start.md index 6dd11238..f70cb991 100644 --- a/docs/src/pages/quick-start.md +++ b/docs/src/pages/quick-start.md @@ -16,24 +16,27 @@ You can add this action for the new project, as well as for already existing one 2. Secondly, make sure that you can run the Jest without additional arguments. To test it, try to run this code in your shell: ```bash - npx jest ``` Or via yarn: ```bash - yarn jest ``` Or via pnpm (pnpx): ```bash - pnpx jest ``` +Or via bun (bunx): + +```bash +bunx jest +``` + If this command is not working for you, see [how to setup custom testing script](https://github.com/ArtiomTr/jest-coverage-report-action#customizing-test-script). diff --git a/src/typings/Options.ts b/src/typings/Options.ts index 6cf3519f..6a36cb38 100644 --- a/src/typings/Options.ts +++ b/src/typings/Options.ts @@ -7,7 +7,7 @@ import { icons } from '../format/strings.json'; export type IconType = keyof typeof icons; export type AnnotationType = 'all' | 'none' | 'coverage' | 'failed-tests'; -export type PackageManagerType = 'npm' | 'yarn' | 'pnpm'; +export type PackageManagerType = 'npm' | 'yarn' | 'pnpm' | 'bun'; export type SkipStepType = 'all' | 'none' | 'install'; export type OutputType = 'comment' | 'report-markdown'; @@ -54,6 +54,7 @@ const packageManagerOptions: Array = [ 'npm', 'yarn', 'pnpm', + 'bun', ]; const validIconOptions = Object.keys(icons); diff --git a/src/utils/getTestCommand.ts b/src/utils/getTestCommand.ts index 3a944c8e..3f403cc5 100644 --- a/src/utils/getTestCommand.ts +++ b/src/utils/getTestCommand.ts @@ -12,13 +12,13 @@ export const getTestCommand = async ( const isNpmStyle = command.startsWith('npm') || command.startsWith('pnpm'); - const hasDoubleHyhen = command.includes(' -- '); + const hasDoubleHyphen = command.includes(' -- '); // building new command const newCommandBuilder: (string | boolean)[] = [ command, // add two hypens if it is npm or pnpm package managers and two hyphens don't already exist - isNpmStyle && !hasDoubleHyhen && '--', + isNpmStyle && !hasDoubleHyphen && '--', // argument which indicates that jest runs in CI environment '--ci', // telling jest that output should be in json format diff --git a/src/utils/isOldScript.ts b/src/utils/isOldScript.ts index d96e887a..45fab40b 100644 --- a/src/utils/isOldScript.ts +++ b/src/utils/isOldScript.ts @@ -2,7 +2,7 @@ import { join } from 'path'; import { readFile } from 'fs-extra'; -const packageScriptRegex = /^(?:(?:npm|yarn|pnpm)\s+(?:run\s+)?([\w:-]+))/; +const packageScriptRegex = /^(?:(?:npm|yarn|pnpm|bun)\s+(?:run\s+)?([\w:-]+))/; export const isOldScript = async ( command: string, diff --git a/tests/stages/getCoverage.test.ts b/tests/stages/getCoverage.test.ts index 030697c8..da31dd70 100644 --- a/tests/stages/getCoverage.test.ts +++ b/tests/stages/getCoverage.test.ts @@ -123,6 +123,21 @@ describe('getCoverage', () => { }); expect(jsonReportPnpm).toStrictEqual({}); + + (readFile as jest.Mock).mockImplementationOnce(() => '{}'); + + const jsonReportBun = await getCoverage( + dataCollector, + { ...defaultOptions, packageManager: 'bun' }, + false, + undefined + ); + + expect(exec).toBeCalledWith('bun install', undefined, { + cwd: undefined, + }); + + expect(jsonReportBun).toStrictEqual({}); }); it('should skip installation step', async () => { diff --git a/tests/stages/installDependencies.test.ts b/tests/stages/installDependencies.test.ts index 06155ed3..8cff5af9 100644 --- a/tests/stages/installDependencies.test.ts +++ b/tests/stages/installDependencies.test.ts @@ -60,6 +60,14 @@ describe('installDependencies', () => { }); }); + it('should install dependencies using bun', async () => { + await installDependencies('bun'); + + expect(exec).toBeCalledWith('bun install', undefined, { + cwd: undefined, + }); + }); + it('should install dependencies under specified working directory', async () => { await installDependencies(undefined, 'workingDir'); diff --git a/tests/utils/getTestCommand.test.ts b/tests/utils/getTestCommand.test.ts index ee1ecc18..1fb33f52 100644 --- a/tests/utils/getTestCommand.test.ts +++ b/tests/utils/getTestCommand.test.ts @@ -17,6 +17,12 @@ describe('getTestCommand', () => { ).toBe( 'pnpx jest --ci --json --coverage --testLocationInResults --outputFile="report.json"' ); + + expect( + await getTestCommand('bunx jest', 'report.json', undefined) + ).toBe( + 'bunx jest --ci --json --coverage --testLocationInResults --outputFile="report.json"' + ); }); it('should add double hyphens for npm and pnpm', async () => { diff --git a/tests/utils/isOldScript.test.ts b/tests/utils/isOldScript.test.ts index ce678b3b..9d9581e1 100644 --- a/tests/utils/isOldScript.test.ts +++ b/tests/utils/isOldScript.test.ts @@ -18,6 +18,10 @@ describe('isOldScript', () => { await isOldScript('pnpx jest --outputFile=report.json', undefined) ).toBe(true); + expect( + await isOldScript('bunx jest --outputFile=report.json', undefined) + ).toBe(true); + expect( await isOldScript('yarn jest --outputFile=report.json', undefined) ).toBe(true); @@ -33,15 +37,24 @@ describe('isOldScript', () => { ) ).toBe(true); + expect( + await isOldScript( + 'bun run test -- --outputFile=report.json', + undefined + ) + ).toBe(true); + expect( await isOldScript('yarn test --outputFile=report.json', undefined) ).toBe(true); expect(await isOldScript('npx jest', undefined)).toBe(false); expect(await isOldScript('pnpx jest', undefined)).toBe(false); + expect(await isOldScript('bunx jest', undefined)).toBe(false); expect(await isOldScript('yarn jest', undefined)).toBe(false); expect(await isOldScript('npm test', undefined)).toBe(false); expect(await isOldScript('pnpm test', undefined)).toBe(false); + expect(await isOldScript('bun run test', undefined)).toBe(false); expect( await isOldScript( 'yaasync async async async async async async async rn test', @@ -67,6 +80,11 @@ describe('isOldScript', () => { expect(await isOldScript('yarn run test:coverage', undefined)).toBe( false ); + expect(await isOldScript('bun run test', undefined)).toBe(true); + expect(await isOldScript('bun run test', undefined)).toBe(true); + expect(await isOldScript('bun run test:coverage', undefined)).toBe( + false + ); expect(await isOldScript('npm run test', undefined)).toBe(true); expect(await isOldScript('npm run test:coverage', undefined)).toBe( false