Skip to content

Commit ea8dd31

Browse files
committed
Full coverage
1 parent 8cfc6a6 commit ea8dd31

32 files changed

+182
-51
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ jobs:
5656
run: pnpm install && pnpm add --global concurrently
5757

5858
- name: Build & Test
59-
run: concurrently --prefix none --group "pnpm:build" "pnpm:test" "pnpm:test:smoke"
59+
run: concurrently --prefix none --group "pnpm:build" "pnpm:test --coverage" "pnpm:test:smoke"
6060

6161
- name: Submit coverage
6262
uses: coverallsapp/github-action@master

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"lint:fix": "pnpm run lint --fix",
3737
"prepublishOnly": "safe-publish-latest && pnpm run build",
3838
"report-coverage": "cat coverage/lcov.info | coveralls",
39-
"test": "vitest --project unit --coverage",
39+
"test": "vitest --project unit",
4040
"test:smoke": "vitest run --project smoke",
4141
"prepare": "husky"
4242
},

src/assert.spec.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { afterEach, describe, expect, it, vi } from 'vitest';
2+
3+
import { assertDeprecated } from './assert';
4+
5+
describe('#assertDeprecated()', () => {
6+
const consoleMock = vi.spyOn(console, 'warn').mockImplementation(() => {});
7+
8+
afterEach(() => {
9+
vi.clearAllMocks();
10+
});
11+
12+
it('prints warning with name and message when condition is false', () => {
13+
assertDeprecated(false, 'example-flag', 'This is an example message.');
14+
15+
expect(consoleMock).toHaveBeenLastCalledWith(
16+
'[concurrently] example-flag is deprecated. This is an example message.',
17+
);
18+
});
19+
20+
it('prints same warning only once', () => {
21+
assertDeprecated(false, 'example-flag', 'This is an example message.');
22+
assertDeprecated(false, 'different-flag', 'This is another message.');
23+
24+
expect(consoleMock).toBeCalledTimes(1);
25+
expect(consoleMock).toHaveBeenLastCalledWith(
26+
'[concurrently] different-flag is deprecated. This is another message.',
27+
);
28+
});
29+
30+
it('prints nothing if condition is true', () => {
31+
assertDeprecated(true, 'example-flag', 'This is an example message.');
32+
33+
expect(consoleMock).not.toHaveBeenCalled();
34+
});
35+
});

src/assert.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const deprecations = new Set<string>();
55
* The message is printed only once.
66
*/
77
export function assertDeprecated(check: boolean, name: string, message: string) {
8-
if (!check) {
8+
if (!check && !deprecations.has(name)) {
99
// eslint-disable-next-line no-console
1010
console.warn(`[concurrently] ${name} is deprecated. ${message}`);
1111
deprecations.add(name);
File renamed without changes.

src/command-parser/expand-arguments.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { quote } from 'shell-quote';
22

33
import { CommandInfo } from '../command';
4-
import { CommandParser } from './command-parser';
4+
import type { CommandParser } from './command-parser';
55

66
/**
77
* Replace placeholders with additional arguments.

src/command-parser/expand-shortcut.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { CommandInfo } from '../command';
2-
import { CommandParser } from './command-parser';
2+
import type { CommandParser } from './command-parser';
33

44
/**
55
* Expands shortcuts according to the following table:

src/command-parser/expand-wildcard.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ describe.each(['npm run', 'yarn run', 'pnpm run', 'bun run', 'node --run'])(
182182

183183
expect(
184184
parser.parse({
185-
name: '',
185+
name: 'watch-*',
186186
command: `${command} watch-*`,
187187
}),
188188
).toEqual([

src/command-parser/expand-wildcard.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import fs from 'fs';
33
import { CommandInfo } from '../command';
44
import JSONC from '../jsonc';
55
import { escapeRegExp } from '../utils';
6-
import { CommandParser } from './command-parser';
6+
import type { CommandParser } from './command-parser';
77

88
// Matches a negative filter surrounded by '(!' and ')'.
99
const OMISSION = /\(!([^)]+)\)/;
@@ -102,7 +102,8 @@ export class ExpandWildcard implements CommandParser {
102102
return;
103103
}
104104

105-
const [, match] = wildcardRegex.exec(script) || [];
105+
const result = wildcardRegex.exec(script);
106+
const match = result?.[1];
106107
if (match !== undefined) {
107108
return {
108109
...commandInfo,

src/command.spec.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,14 @@ describe('#start()', () => {
107107
expect(command.stdin).toBe(process.stdin);
108108
});
109109

110+
it('handles process with no stdin', () => {
111+
process.stdin = null;
112+
const { command } = createCommand();
113+
command.start();
114+
115+
expect(command.stdin).toBe(undefined);
116+
});
117+
110118
it('changes state to started', () => {
111119
const { command } = createCommand();
112120
const spy = subscribeSpyTo(command.stateChange);

0 commit comments

Comments
 (0)