Skip to content
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

Add Bun package manager #401

Merged
merged 3 commits into from
Nov 2, 2023
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
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 9 additions & 1 deletion docs/src/pages/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down
9 changes: 6 additions & 3 deletions docs/src/pages/quick-start.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```

<!-- TODO: replace link -->

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).
Expand Down
3 changes: 2 additions & 1 deletion src/typings/Options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -54,6 +54,7 @@ const packageManagerOptions: Array<PackageManagerType> = [
'npm',
'yarn',
'pnpm',
'bun',
];

const validIconOptions = Object.keys(icons);
Expand Down
4 changes: 2 additions & 2 deletions src/utils/getTestCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ export const getTestCommand = async (

const isNpmStyle = command.startsWith('npm') || command.startsWith('pnpm');

const hasDoubleHyhen = command.includes(' -- ');
const hasDoubleHyphen = command.includes(' -- ');
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor typo (unrelated to Bun integration)


// 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
Expand Down
2 changes: 1 addition & 1 deletion src/utils/isOldScript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
15 changes: 15 additions & 0 deletions tests/stages/getCoverage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,21 @@ describe('getCoverage', () => {
});

expect(jsonReportPnpm).toStrictEqual({});

(readFile as jest.Mock<any, any>).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 () => {
Expand Down
8 changes: 8 additions & 0 deletions tests/stages/installDependencies.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down
6 changes: 6 additions & 0 deletions tests/utils/getTestCommand.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
18 changes: 18 additions & 0 deletions tests/utils/isOldScript.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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',
Expand All @@ -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
Expand Down