Skip to content

Commit 026a012

Browse files
authoredJan 24, 2021
test: stop using npm link in CLI tests (#251)
1 parent f14c912 commit 026a012

File tree

1 file changed

+45
-32
lines changed

1 file changed

+45
-32
lines changed
 

‎test/test.cli.ts

+45-32
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,11 @@ import {LinkResult, LinkState} from '../src/index';
99
// eslint-disable-next-line prefer-arrow-callback
1010
describe('cli', function () {
1111
let server: http.Server;
12-
this.timeout(60_000);
12+
this.timeout(10_000);
Has conversations. Original line has conversations.
1313

14-
if (process.env.LINKINATOR_SKIP_CLI_TESTS) {
15-
return;
16-
}
17-
18-
before(async () => {
19-
await execa('npm', ['link']);
20-
});
14+
const pkg = require('../../package.json');
15+
const linkinator = pkg.bin.linkinator;
16+
const node = 'node';
2117

2218
afterEach(async () => {
2319
if (server) {
@@ -26,34 +22,39 @@ describe('cli', function () {
2622
});
2723

2824
it('should show output for failures', async () => {
29-
const res = await execa('linkinator', ['test/fixtures/basic'], {
25+
const res = await execa(node, [linkinator, 'test/fixtures/basic'], {
3026
reject: false,
3127
});
3228
assert.match(res.stderr, /ERROR: Detected 1 broken links/);
3329
});
3430

3531
it('should pass successful markdown scan', async () => {
36-
const res = await execa('linkinator', ['test/fixtures/markdown/README.md']);
32+
const res = await execa(node, [
33+
linkinator,
34+
'test/fixtures/markdown/README.md',
35+
]);
3736
assert.match(res.stderr, /Successfully scanned/);
3837
});
3938

4039
it('should allow multiple paths', async () => {
41-
const res = await execa('linkinator', [
40+
const res = await execa(node, [
41+
linkinator,
4242
'test/fixtures/markdown/unlinked.md',
4343
'test/fixtures/markdown/README.md',
4444
]);
4545
assert.match(res.stderr, /Successfully scanned/);
4646
});
4747

4848
it('should show help if no params are provided', async () => {
49-
const res = await execa('linkinator', {
49+
const res = await execa(node, [linkinator], {
5050
reject: false,
5151
});
5252
assert.match(res.stdout, /\$ linkinator LOCATION \[ --arguments \]/);
5353
});
5454

5555
it('should flag skipped links', async () => {
56-
const res = await execa('linkinator', [
56+
const res = await execa(node, [
57+
linkinator,
5758
'--verbosity',
5859
'INFO',
5960
'--skip',
@@ -64,7 +65,8 @@ describe('cli', function () {
6465
});
6566

6667
it('should provide CSV if asked nicely', async () => {
67-
const res = await execa('linkinator', [
68+
const res = await execa(node, [
69+
linkinator,
6870
'--format',
6971
'csv',
7072
'test/fixtures/markdown/README.md',
@@ -73,7 +75,8 @@ describe('cli', function () {
7375
});
7476

7577
it('should provide JSON if asked nicely', async () => {
76-
const res = await execa('linkinator', [
78+
const res = await execa(node, [
79+
linkinator,
7780
'--format',
7881
'json',
7982
'test/fixtures/markdown/README.md',
@@ -83,15 +86,17 @@ describe('cli', function () {
8386
});
8487

8588
it('should not show links if --silent', async () => {
86-
const res = await execa('linkinator', [
89+
const res = await execa(node, [
90+
linkinator,
8791
'--silent',
8892
'test/fixtures/markdown/README.md',
8993
]);
9094
assert.notMatch(res.stdout, /\[/);
9195
});
9296

9397
it('should not show 200 links if verbosity is ERROR with JSON', async () => {
94-
const res = await execa('linkinator', [
98+
const res = await execa(node, [
99+
linkinator,
95100
'--verbosity',
96101
'ERROR',
97102
'--format',
@@ -105,7 +110,8 @@ describe('cli', function () {
105110
});
106111

107112
it('should accept a server-root', async () => {
108-
const res = await execa('linkinator', [
113+
const res = await execa(node, [
114+
linkinator,
109115
'--markdown',
110116
'--server-root',
111117
'test/fixtures/markdown',
@@ -115,24 +121,29 @@ describe('cli', function () {
115121
});
116122

117123
it('should accept globs', async () => {
118-
const res = await execa('linkinator', [
124+
const res = await execa(node, [
125+
linkinator,
119126
'test/fixtures/markdown/*.md',
120127
'test/fixtures/markdown/**/*.md',
121128
]);
122129
assert.match(res.stderr, /Successfully scanned/);
123130
});
124131

125132
it('should throw on invalid format', async () => {
126-
const res = await execa('linkinator', ['./README.md', '--format', 'LOL'], {
127-
reject: false,
128-
});
133+
const res = await execa(
134+
node,
135+
[linkinator, './README.md', '--format', 'LOL'],
136+
{
137+
reject: false,
138+
}
139+
);
129140
assert.match(res.stderr, /FORMAT must be/);
130141
});
131142

132143
it('should throw on invalid verbosity', async () => {
133144
const res = await execa(
134-
'linkinator',
135-
['./README.md', '--VERBOSITY', 'LOL'],
145+
node,
146+
[linkinator, './README.md', '--VERBOSITY', 'LOL'],
136147
{
137148
reject: false,
138149
}
@@ -142,8 +153,8 @@ describe('cli', function () {
142153

143154
it('should throw when verbosity and silent are flagged', async () => {
144155
const res = await execa(
145-
'linkinator',
146-
['./README.md', '--verbosity', 'DEBUG', '--silent'],
156+
node,
157+
[linkinator, './README.md', '--verbosity', 'DEBUG', '--silent'],
147158
{
148159
reject: false,
149160
}
@@ -153,8 +164,8 @@ describe('cli', function () {
153164

154165
it('should show no output for verbosity=NONE', async () => {
155166
const res = await execa(
156-
'linkinator',
157-
['test/fixtures/basic', '--verbosity', 'NONE'],
167+
node,
168+
[linkinator, 'test/fixtures/basic', '--verbosity', 'NONE'],
158169
{
159170
reject: false,
160171
}
@@ -166,8 +177,8 @@ describe('cli', function () {
166177

167178
it('should show callstacks for verbosity=DEBUG', async () => {
168179
const res = await execa(
169-
'linkinator',
170-
['test/fixtures/basic', '--verbosity', 'DEBUG'],
180+
node,
181+
[linkinator, 'test/fixtures/basic', '--verbosity', 'DEBUG'],
171182
{
172183
reject: false,
173184
}
@@ -177,7 +188,8 @@ describe('cli', function () {
177188
});
178189

179190
it('should allow passing a config', async () => {
180-
const res = await execa('linkinator', [
191+
const res = await execa(node, [
192+
linkinator,
181193
'test/fixtures/basic',
182194
'--config',
183195
'test/fixtures/config/skip-array-config.json',
@@ -207,7 +219,8 @@ describe('cli', function () {
207219
enableDestroy(server);
208220
await new Promise<void>(r => server.listen(port, r));
209221

210-
const res = await execa('linkinator', [
222+
const res = await execa(node, [
223+
linkinator,
211224
'--retry',
212225
'test/fixtures/retryCLI',
213226
]);

0 commit comments

Comments
 (0)
Please sign in to comment.