Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enforce test coverage, tolerate gaps, and begin to remove them #175

Merged
merged 3 commits into from
Jun 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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