Skip to content

Commit

Permalink
fix: move test utilities to lib/ and rely directly on expect (#101)
Browse files Browse the repository at this point in the history
* fix: move test utilities to lib/ and rely directly on `expect`

this removes any need to include test code in the published package and avoids mixing dev dependencies into the published dependencies

also, update axios-cookie-support to use the latest release and add tough-cookie, as it is now a required peer dependency
  • Loading branch information
dpopp07 committed Jul 22, 2020
1 parent 80f2376 commit 57ca4c2
Show file tree
Hide file tree
Showing 7 changed files with 2,020 additions and 2,440 deletions.
4 changes: 1 addition & 3 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
test/resources
test/unit
test/.eslintrc.js
test
coverage
.jshintignore
.hshintrc
Expand Down
4 changes: 3 additions & 1 deletion index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,6 @@ export * from './lib/helper';
export { default as qs } from './lib/querystring';
export { default as contentType } from './lib/content-type';
export * from './lib/stream-to-promise';
export * from './test/utils';

import * as unitTestUtils from './lib/sdk-test-helpers';
export { unitTestUtils };
7 changes: 2 additions & 5 deletions test/utils/unit-test-helpers.ts → lib/sdk-test-helpers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2019 IBM Corp. All Rights Reserved.
* Copyright 2019, 2020 IBM Corp. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -14,15 +14,12 @@
* limitations under the License.
*/

/* istanbul ignore file */
import expect = require('expect');

/**
* This module provides a set of helper methods used to reduce code duplication in the generated unit tests
* for the SDKs that depend on this core package. Note that these methods are not used by the tests for this
* package - they are meant to be exported and made available to dependent libraries.
*
* They are included in the `test` directory since they rely on `jest` globals (like `expect`) and this
* requires special linting rules that should not be configured in the rest of the source code.
*/

/**
Expand Down
4,408 changes: 2,010 additions & 2,398 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@
"@types/extend": "~3.0.0",
"@types/file-type": "~5.2.1",
"@types/isstream": "^0.1.0",
"@types/jest": "^24.0.23",
"@types/node": "~10.14.19",
"axios": "^0.18.1",
"axios-cookiejar-support": "^0.5.1",
"axios-cookiejar-support": "^1.0.0",
"camelcase": "^5.3.1",
"debug": "^4.1.1",
"dotenv": "^6.2.0",
"expect": "^26.1.0",
"extend": "~3.0.2",
"file-type": "^7.7.1",
"form-data": "^2.3.3",
Expand All @@ -72,7 +72,7 @@
"object.omit": "~3.0.0",
"object.pick": "~1.3.0",
"semver": "^6.2.0",
"ts-jest": "^25.5.1"
"tough-cookie": "^4.0.0"
},
"browser": {
"./auth/utils/read-credentials-file": "./auth/utils/read-credentials-file.browser"
Expand Down
6 changes: 1 addition & 5 deletions test/unit/cookiejar.test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
'use strict';

// the `toBeInstanceOf` assertion compares for function reference equality
// importing our own `tough-cookie` dependency would create a different function
// reference and render the assertion unusable. the solution is to use the
// dependency within axios-cookiejar-support
const tough = require('axios-cookiejar-support/node_modules/tough-cookie');
const tough = require('tough-cookie');
const { RequestWrapper } = require('../../dist/lib/request-wrapper');

describe('cookie jar support', () => {
Expand Down
25 changes: 0 additions & 25 deletions test/utils/index.ts

This file was deleted.

0 comments on commit 57ca4c2

Please sign in to comment.