Skip to content

Commit db013b4

Browse files
author
Phil Sturgeon
committed
Moved tests into a lib dir
This will make room for command tests
1 parent 76da736 commit db013b4

24 files changed

+28
-134
lines changed

.circleci/config.yml

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@ version: 2.1
33
commands:
44
# Command based on instructions from CircleCI blog for avoiding fork secret leakage or failures
55
# https://circleci.com/blog/managing-secrets-when-you-have-pull-requests-from-outside-contributors/
6-
coverage:
6+
early-return-forks:
77
description: >-
8-
Report coverage, and send to Coveralls if its not a fork.
8+
If this build is from a fork, stop executing the current job and return success.
9+
This is useful to avoid steps that will fail due to missing credentials.
910
steps:
1011
- run:
11-
name: Coverage
12+
name: Early return if this build is from a forked PR
1213
command: |
1314
if [ -n "$CIRCLE_PR_NUMBER" ]; then
14-
npm run coverage
15-
else
16-
npm run coverage | coveralls
15+
echo "Nothing to do for forked PRs, so marking this step successful"
16+
circleci step halt
1717
fi
1818
1919
install-and-test:
@@ -33,8 +33,13 @@ commands:
3333
key: dependency-cache-{{ checksum "package.json" }}
3434
paths:
3535
- node_modules
36-
- run: npm test
37-
- coverage
36+
- run:
37+
name: Tests
38+
command: npx jest --ci --coverage
39+
- early-return-forks
40+
- run:
41+
name: Report Coverage
42+
command: npx coveralls < coverage/lcov.info
3843

3944
jobs:
4045
node-latest:
File renamed without changes.
File renamed without changes.

package.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
"speccy": "./speccy.js"
88
},
99
"scripts": {
10-
"test": "nyc --reporter=html --reporter=text mocha",
11-
"coverage": "nyc report --reporter=text-lcov"
10+
"test": "jest --coverage"
1211
},
1312
"preferGlobal": true,
1413
"repository": {
@@ -52,7 +51,6 @@
5251
"babel-preset-es2015": "^6.24.1",
5352
"coveralls": "^3.0.0",
5453
"jest": "^23.6.0",
55-
"nock": "^10.0.0",
56-
"nyc": "^13.0.0"
54+
"nock": "^10.0.0"
5755
}
5856
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

test/config.test.js renamed to test/lib/config.test.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
'use strict';
22

3-
const config = require('../lib/config.js');
3+
const config = require('../../lib/config.js');
44

55
describe('Config', () => {
66
describe('init()', () => {
77
test('does not throw for invalid file', () => {
8-
const configFile = 'test/config/doesnotexist.yaml';
8+
const configFile = 'test/fixtures/config/doesnotexist.yaml';
99
const f = () => { config.init({ config: configFile }); }
1010
expect(f).not.toThrow;
1111
});
1212

1313
describe('with a valid json file', () => {
14-
const configFile = 'test/config/valid.json';
14+
const configFile = 'test/fixtures/config/valid.json';
1515

1616
test('can find expected values', () => {
1717
config.init({ config: configFile });
@@ -22,7 +22,7 @@ describe('Config', () => {
2222
});
2323

2424
describe('with a valid yaml file', () => {
25-
const configFile = 'test/config/valid.yaml';
25+
const configFile = 'test/fixtures/config/valid.yaml';
2626

2727
test('can find expected values', () => {
2828
config.init({ config: configFile });
@@ -43,7 +43,7 @@ describe('Config', () => {
4343

4444
describe('load()', () => {
4545
describe('when an empty file is loaded', () => {
46-
const configFile = 'test/config/empty.yaml';
46+
const configFile = 'test/fixtures/config/empty.yaml';
4747

4848
describe('and no config options are supplied', () => {
4949
test('it will have undefined values', () => {

test/linter.test.js renamed to test/lib/linter.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
const fs = require('fs');
44
const path = require('path');
5-
const loader = require('../lib/loader.js');
6-
const linter = require('../lib/linter.js');
5+
const loader = require('../../lib/loader.js');
6+
const linter = require('../../lib/linter.js');
77

88
const runLinter = (object, input, key, options = {}) => {
99
return linter.lint(object, input, key, options);
@@ -45,7 +45,7 @@ const testFixture = (fixture, rules) => {
4545

4646
describe('Linter', () => {
4747
describe('lint()', () => {
48-
const profilesDir = path.join(__dirname, './profiles/');
48+
const profilesDir = path.join(__dirname, '../fixtures/profiles/');
4949

5050
['default', 'strict'].forEach(profileName => {
5151
const profile = JSON.parse(fs.readFileSync(profilesDir + profileName + '.json', 'utf8'))

test/loader.test.js renamed to test/lib/loader.test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22

33
const fetch = require('node-fetch');
4-
const loader = require('../lib/loader.js');
4+
const loader = require('../../lib/loader.js');
55
const nock = require('nock');
66
const path = require('path');
77
const yaml = require('js-yaml');
@@ -23,7 +23,7 @@ describe('Loader', () => {
2323

2424
describe('when loading from a local file', () => {
2525
test('retrieves rules from the file', () => {
26-
const file = __dirname + '/../rules/strict.json';
26+
const file = __dirname + '/../../rules/strict.json';
2727
return expect(loader.loadRuleFiles([file])).resolves.toEqual([file, 'default']);
2828
})
2929
})
@@ -33,7 +33,7 @@ describe('Loader', () => {
3333
const url = host + '/';
3434

3535
test('retrieves rules from valid url', () => {
36-
nock(host).get('/').replyWithFile(200, __dirname + '/../rules/strict.json', {
36+
nock(host).get('/').replyWithFile(200, __dirname + '/../../rules/strict.json', {
3737
'Content-Type': 'application/json'
3838
});
3939

@@ -61,7 +61,7 @@ describe('Loader', () => {
6161
});
6262

6363
describe('loadSpec()', () => {
64-
const samplesDir = path.join(__dirname, './samples/');
64+
const samplesDir = path.join(__dirname, '../fixtures/loader/');
6565

6666
test('loads json specs', async () => {
6767
const spec = await loader.loadSpec(samplesDir + 'openapi.json');

test/server.test.js renamed to test/lib/server.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
const server = require('../lib/server.js');
3+
const server = require('../../lib/server.js');
44

55
describe('Server', () => {
66
describe('loadHTML()', () => {

test/samples/remote-ref-success.yaml

Lines changed: 0 additions & 109 deletions
This file was deleted.

0 commit comments

Comments
 (0)