Skip to content

Commit 9034fc7

Browse files
authored
Merge pull request #19 from Arcanemagus/tests
Add basic tests using Jest
2 parents 26e4973 + 7871873 commit 9034fc7

File tree

16 files changed

+3837
-110
lines changed

16 files changed

+3837
-110
lines changed

.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Remove some files from the released version
2+
__tests__/*
23
.npmignore
34
.gitignore
45
.gitattributes

__tests__/.eslintrc.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
"env": {
3+
"jest": true,
4+
}
5+
};

__tests__/check-peer-deps.test.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
const { exec: execCP } = require('child_process');
2+
const { promisify } = require('util');
3+
const path = require('path');
4+
5+
const exec = promisify(execCP);
6+
7+
const cpdBinPath = path.join(__dirname, '..', 'bin', 'check-peer-deps-cli.js');
8+
const fixtures = path.join(__dirname, 'fixtures');
9+
10+
const EXEC_TIMEOUT = 20 * 1000; // 20 * 1000 ms = 20 seconds
11+
12+
const runCPD = async (args = [], options = {}) => {
13+
jest.setTimeout(EXEC_TIMEOUT);
14+
const command = [`"${process.execPath}"`, `"${cpdBinPath}"`]
15+
.concat(args).join(' ');
16+
return exec(command, options);
17+
};
18+
19+
test('Finds nothing wrong with a good dependency tree', async () => {
20+
expect.assertions(2);
21+
const output = await runCPD([], { cwd: path.join(fixtures, 'goodDep') });
22+
expect(output.stdout).toBe('');
23+
expect(output.stderr).toBe('');
24+
});
25+
26+
test('Finds the missing dependencies in a broken tree', async () => {
27+
expect.assertions(3);
28+
const output = await runCPD([], { cwd: path.join(fixtures, 'missingDep') });
29+
expect(output.stdout).toBe('');
30+
const issues = output.stderr.split('\n');
31+
expect(issues[0]).toBe("A dependency satisfying eslint-config-airbnb-base's " +
32+
"peerDependency of 'eslint@^4.9.0' was not found!");
33+
expect(issues[1]).toBe("A dependency satisfying eslint-config-airbnb-base's " +
34+
"peerDependency of 'eslint-plugin-import@^2.7.0' was not found!");
35+
});
36+
37+
test('Finds nothing wrong with no peerDependencies in the tree', async () => {
38+
expect.assertions(2);
39+
const output = await runCPD([], { cwd: path.join(fixtures, 'noPeerDeps') });
40+
expect(output.stdout).toBe('');
41+
expect(output.stderr).toBe('');
42+
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
!node_modules/

__tests__/fixtures/goodDep/node_modules/eslint-config-airbnb-base/package.json

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

__tests__/fixtures/goodDep/node_modules/eslint-plugin-import/package.json

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

__tests__/fixtures/goodDep/node_modules/eslint/package.json

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"dependencies": {
3+
"eslint": "4.9.0",
4+
"eslint-config-airbnb-base": "12.1.0",
5+
"eslint-plugin-import": "2.7.0"
6+
}
7+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
!node_modules/

__tests__/fixtures/missingDep/node_modules/eslint-config-airbnb-base/package.json

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)