Skip to content

Commit

Permalink
Enforce test coverage, tolerate gaps, and begin to remove them (#175)
Browse files Browse the repository at this point in the history
* Enforce 100% code coverage

* Enable test coverage verification for test helper

Some code paths which are intended to improve error reports for test
failures. They are not expected to be used when all tests are passing.

Tolerate coverage gaps for these specific code paths.

* Improve coverage for `Airtable` interface
  • Loading branch information
jugglinmike authored Jun 2, 2020
1 parent f8f793b commit ce447fb
Show file tree
Hide file tree
Showing 16 changed files with 99 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
node_modules
/.nyc_output/
/coverage/
1 change: 1 addition & 0 deletions lib/airtable_error.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// istanbul ignore file
'use strict';

function AirtableError(error, message, statusCode) {
Expand Down
1 change: 1 addition & 0 deletions lib/base.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// istanbul ignore file
'use strict';

var forEach = require('lodash/forEach');
Expand Down
1 change: 1 addition & 0 deletions lib/callback_to_promise.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// istanbul ignore file
'use strict';

var Promise = require('./promise');
Expand Down
1 change: 1 addition & 0 deletions lib/deprecate.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// istanbul ignore file
'use strict';

var didWarnForDeprecation = {};
Expand Down
1 change: 1 addition & 0 deletions lib/http_headers.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// istanbul ignore file
var forEach = require('lodash/forEach');

var isBrowser = typeof window !== 'undefined';
Expand Down
1 change: 1 addition & 0 deletions lib/object_to_query_param_string.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// istanbul ignore file
'use strict';

var isArray = require('lodash/isArray');
Expand Down
1 change: 1 addition & 0 deletions lib/promise.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// istanbul ignore file
/* global Promise */
var polyfill = require('es6-promise');

Expand Down
1 change: 1 addition & 0 deletions lib/query.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// istanbul ignore file
'use strict';

var isPlainObject = require('lodash/isPlainObject');
Expand Down
1 change: 1 addition & 0 deletions lib/record.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// istanbul ignore file
'use strict';

var assign = require('lodash/assign');
Expand Down
1 change: 1 addition & 0 deletions lib/run_action.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// istanbul ignore file
'use strict';

var exponentialBackoffWithJitter = require('./exponential_backoff_with_jitter');
Expand Down
1 change: 1 addition & 0 deletions lib/table.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// istanbul ignore file
'use strict';

var isArray = require('lodash/isArray');
Expand Down
1 change: 1 addition & 0 deletions lib/typecheck.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// istanbul ignore file
'use strict';

var includes = require('lodash/includes');
Expand Down
14 changes: 13 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
"repository": "git://github.com/airtable/airtable.js.git",
"private": false,
"scripts": {
"coverage": "jest --env node --coverage",
"pretest": "npm run lint",
"lint": "eslint .",
"format": "prettier --write '**/*.js'",
"test": "jest --env node"
"test": "npm run coverage && npm run test-unit",
"test-unit": "jest --env node"
},
"dependencies": {
"es6-promise": "4.2.8",
Expand All @@ -29,6 +31,16 @@
"/build/airtable.browser.js",
"/lib/"
],
"jest": {
"coverageThreshold": {
"global": {
"branches": 100,
"functions": 100,
"lines": 100,
"statements": 100
}
}
},
"devDependencies": {
"body-parser": "^1.19.0",
"envify": "^4.1.0",
Expand Down
69 changes: 69 additions & 0 deletions test/airtable.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,73 @@ describe('Airtable', function() {
expect(value).not.toEqual('keyXyz');
});
});

it('recognizes API key as a property of the constructor', function() {
try {
Airtable.apiKey = 'keyAbc';
new Airtable({});
new Airtable();
} finally {
delete Airtable.apiKey;
}
});

it('recognizes API key as an environment variable', function() {
try {
process.env.AIRTABLE_API_KEY = 'keyDef';
new Airtable({});
new Airtable();
} finally {
delete process.env.AIRTABLE_API_KEY;
}
});

it('throws when API key is not provided', function() {
expect(function() {
new Airtable({});
}).toThrow();

expect(function() {
new Airtable();
}).toThrow();
});

describe('configure static method', function() {
it('sets the apiKey', function() {
Airtable.configure({apiKey: 'keyGhi'});

try {
expect(Airtable.apiKey).toEqual('keyGhi');
} finally {
delete Airtable.apiKey;
}
});
});

describe('base static method', function() {
it('throws in the absense of an API key', function() {
expect(function() {
Airtable.base('abaseid');
});
});

it('returns a Base instance configured with the given ID', function() {
try {
Airtable.apiKey = 'keyJkl';
var base = Airtable.base('abaseid');

expect(base.getId()).toBe('abaseid');
} finally {
delete Airtable.apiKey;
}
});
});

describe('base instance method', function() {
it('returns a Base instance configured with the given ID', function() {
var base = new Airtable({apiKey: 'keyMno'}).base('anotherbaseid');

expect(base.getId()).toBe('anotherbaseid');
});
});
});
3 changes: 3 additions & 0 deletions test/test_helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ function getMockEnvironmentAsync(options) {
res.json({error: 'NOT_FOUND'});
});

// istanbul ignore next
// eslint-disable-next-line no-unused-vars
app.use(function(err, req, res, next) {
console.error(err);
Expand All @@ -134,6 +135,7 @@ function getMockEnvironmentAsync(options) {
}

testServer.listen(testServerPort, function(err) {
// istanbul ignore if
if (err) {
reject(err);
} else {
Expand All @@ -156,6 +158,7 @@ function _checkParamsMiddleware(req, res, next) {
req.get('authorization') === 'Bearer key123' &&
req.params.baseId === 'app123' &&
req.params.tableIdOrName === 'Table';
// istanbul ignore else
if (areParamsValid) {
next();
} else {
Expand Down

0 comments on commit ce447fb

Please sign in to comment.