Skip to content

Commit

Permalink
refactor: upgrade deps, switch to lefthook, fix tests (#1016)
Browse files Browse the repository at this point in the history
* refactor: upgrade deps, switch to lefthook, fix tests

karma-typescript is not working with TS 4.5.4, thus downgraded to TS 4.4.4 until this will be fixed. See monounity/karma-typescript#499 for more details.

* test: remove IE11 and Linux Chrome 48 from test matrix, as those are outdated browsers

* test: transpile fetch-mock bundle to es5 syntax to make ancient browsers happy

fetch-mock's client-legacy-bundle was throwing an exception during execution.

* test: remove IE11 and non-chromium Edge browsers from test matrix as they are dead

* test: make tests work for latest browsers

* test: make tests work for latest browsers
  • Loading branch information
bhovhannes authored Jan 10, 2022
1 parent 31792b2 commit dcb1cf5
Show file tree
Hide file tree
Showing 25 changed files with 559 additions and 1,046 deletions.
5 changes: 0 additions & 5 deletions .huskyrc.json

This file was deleted.

4 changes: 0 additions & 4 deletions .lintstagedrc.json

This file was deleted.

36 changes: 2 additions & 34 deletions karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module.exports = function (config) {
// list of files / patterns to load in the browser
files: [
'node_modules/whatwg-fetch/dist/fetch.umd.js',
'node_modules/fetch-mock/dist/es5/client-bundle.js',
'node_modules/fetch-mock/es5/client-bundle.js',
'node_modules/should/should.js',
{
pattern: 'test/integration/*.spec.ts',
Expand Down Expand Up @@ -115,20 +115,6 @@ module.exports = function (config) {
browserName: 'safari',
base: 'SauceLabs',
},
SL_Safari_9: {
version: '9.0',
platform: 'OS X 10.11',
browserName: 'safari',
base: 'SauceLabs',
},
}
const ie = {
SL_InternetExplorer_11: {
version: '11.0',
platform: 'Windows 7',
browserName: 'internet explorer',
base: 'SauceLabs',
},
}
const edge = {
SL_Edge_Latest: {
Expand All @@ -137,26 +123,8 @@ module.exports = function (config) {
browserName: 'MicrosoftEdge',
base: 'SauceLabs',
},
SL_Edge_14: {
version: '14.14393',
platform: 'Windows 10',
browserName: 'MicrosoftEdge',
base: 'SauceLabs',
},
SL_Edge_13: {
version: '13.10586',
platform: 'Windows 10',
browserName: 'MicrosoftEdge',
base: 'SauceLabs',
},
}
const linux = {
SL_Chrome_Linux: {
version: 'latest',
platform: 'Linux',
browserName: 'chrome',
base: 'SauceLabs',
},
SL_Firefox_Linux: {
version: 'latest',
platform: 'Linux',
Expand All @@ -166,7 +134,7 @@ module.exports = function (config) {
}

// Browsers to run on Sauce Labs
const customLaunchers = Object.assign({}, chrome, firefox, safari, ie, edge, linux)
const customLaunchers = Object.assign({}, chrome, firefox, safari, edge, linux)

// Override config for CI.
config.set({
Expand Down
9 changes: 9 additions & 0 deletions lefthook.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
pre-commit:
parallel: false
commands:
format:
glob: '*.{ts,js,css,md}'
run: yarn prettier --write {staged_files} && git add {staged_files}
lint:
glob: '*.{ts}'
run: yarn tslint --fix {staged_files} && git add {staged_files}
18 changes: 8 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,29 @@
"sideEffects": false,
"typings": "typings/Api.d.ts",
"dependencies": {
"@types/node": "^16.0.0",
"@types/node": "^17.0.8",
"form-data": "^4.0.0",
"isomorphic-fetch": "^3.0.0",
"tslib": "^2.0.1",
"tslib": "^2.3.1",
"workfront-api-constants": "^2.0.0"
},
"devDependencies": {
"@arkweid/lefthook": "0.7.7",
"@rollup/plugin-commonjs": "21.0.1",
"@rollup/plugin-json": "4.1.0",
"@rollup/plugin-node-resolve": "13.1.3",
"@rollup/plugin-typescript": "8.3.0",
"@types/mocha": "9.0.0",
"conventional-changelog-cli": "2.2.2",
"fetch-mock": "6.5.2",
"http-server": "13.0.2",
"husky": "4.3.8",
"karma": "5.2.3",
"fetch-mock": "9.11.0",
"http-server": "14.0.0",
"karma": "6.3.10",
"karma-chrome-launcher": "3.1.0",
"karma-cli": "2.0.0",
"karma-mocha": "2.0.1",
"karma-sauce-launcher": "4.3.6",
"karma-typescript": "5.5.2",
"karma-typescript-es6-transform": "5.5.2",
"lint-staged": "12.1.5",
"mocha": "9.1.3",
"npm-run-all": "4.1.5",
"prettier": "2.5.1",
Expand All @@ -45,12 +44,11 @@
"tslint": "6.1.3",
"tslint-config-prettier": "1.18.0",
"typedoc": "0.22.10",
"typescript": "4.5.4",
"typescript": "4.4.4",
"uuid": "8.3.2"
},
"scripts": {
"precommit": "lint-staged",
"prettier": "prettier --write **/*.{ts,tsx,js,css,md}",
"prettier": "prettier --write **/*.{ts,js,css,md}",
"test": "run-s test:*",
"test:karma": "karma start karma.conf.js",
"test:mocha": "mocha -r ts-node/register/transpile-only test/*.spec.ts",
Expand Down
6 changes: 3 additions & 3 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module.exports = [
sourcemap: true,
},
],
plugins: [typescript(), nodeResolve(), commonjs()],
plugins: [typescript({module: 'es6'}), nodeResolve(), commonjs()],
},
{
input: 'src/Api.ts',
Expand All @@ -43,7 +43,7 @@ module.exports = [
name: 'Wokfront',
sourcemap: true,
},
plugins: [typescript(), nodeResolve(), commonjs(), terser()],
plugins: [typescript({module: 'es6'}), nodeResolve(), commonjs(), terser()],
},
{
input: 'src/node.ts',
Expand All @@ -53,7 +53,7 @@ module.exports = [
sourcemap: true,
exports: 'named',
},
plugins: [typescript(), commonjs({extensions: ['.js', '.ts']})],
plugins: [typescript({module: 'es6'}), commonjs({extensions: ['.js', '.ts']})],
external: ['tslib', 'form-data', 'isomorphic-fetch', 'workfront-api-constants'],
},
]
26 changes: 13 additions & 13 deletions src/Api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -712,43 +712,43 @@ function batchApiFactory(api: Api): IBatchApi {
fields?: TFields,
options?: string[]
) => {
return (apiClone.copy(objCode, objID, updates, fields, options) as any) as string
return apiClone.copy(objCode, objID, updates, fields, options) as any as string
},
count: (objCode: string, query?: object) => {
return (apiClone.count(objCode, query) as any) as string
return apiClone.count(objCode, query) as any as string
},
create: (objCode: string, params: any, fields?: TFields) => {
return (apiClone.create(objCode, params, fields) as any) as string
return apiClone.create(objCode, params, fields) as any as string
},
edit: (objCode: string, objID: string, updates: any, fields?: TFields) => {
return (apiClone.edit(objCode, objID, updates, fields) as any) as string
return apiClone.edit(objCode, objID, updates, fields) as any as string
},
editMultiple: (objCode: string, updates: any[], fields?: TFields) => {
return (apiClone.editMultiple(objCode, updates, fields) as any) as string
return apiClone.editMultiple(objCode, updates, fields) as any as string
},
execute: (objCode: string, objID: string | null, action: string, actionArgs?: object) => {
return (apiClone.execute(objCode, objID, action, actionArgs) as any) as string
return apiClone.execute(objCode, objID, action, actionArgs) as any as string
},
get: (objCode: string, objIDs: string | string[], fields?: TFields) => {
return (apiClone.get(objCode, objIDs, fields) as any) as string
return apiClone.get(objCode, objIDs, fields) as any as string
},
metadata: (objCode?: string, fields?: TFields) => {
return (apiClone.metadata(objCode, fields) as any) as string
return apiClone.metadata(objCode, fields) as any as string
},
namedQuery: (objCode: string, query: string, queryArgs?: object, fields?: TFields) => {
return (apiClone.namedQuery(objCode, query, queryArgs, fields) as any) as string
return apiClone.namedQuery(objCode, query, queryArgs, fields) as any as string
},
remove: (objCode: string, objID: string, bForce?: boolean) => {
return (apiClone.remove(objCode, objID, bForce) as any) as string
return apiClone.remove(objCode, objID, bForce) as any as string
},
report: (objCode: string, query: object) => {
return (apiClone.report(objCode, query) as any) as string
return apiClone.report(objCode, query) as any as string
},
request: (path: string, params, fields?: TFields, method: string = Api.Methods.GET) => {
return (apiClone.request(path, params, fields, method) as any) as string
return apiClone.request(path, params, fields, method) as any as string
},
search: (objCode: string, query?: object, fields?: TFields) => {
return (apiClone.search(objCode, query, fields, false) as any) as string
return apiClone.search(objCode, query, fields, false) as any as string
},
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class NodeApi extends BaseApi {
return makeFetchCall(this._httpOptions.url + this._httpOptions.path + '/upload', {
headers: this.getHeaders(),
body: data as any,
method: BaseApi.Methods.POST
method: BaseApi.Methods.POST,
})
}
}
Expand Down
9 changes: 4 additions & 5 deletions test/integration/batch.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,15 @@
* limitations under the License.
*/

import * as fetchMock from 'fetch-mock'
import fetchMock from 'fetch-mock'
import should from 'should'
import {Api} from '../../src/Api'
import fixture from '../../fixtures/batch.json'

const API_URL = 'http://foobar:8080'

describe('Batch', function () {
afterEach(fetchMock.reset)
afterEach(fetchMock.restore)
afterEach(() => fetchMock.reset())

beforeEach(function () {
this.api = new Api({
Expand Down Expand Up @@ -88,14 +87,14 @@ describe('Batch', function () {

it('should contain 3 uri params in its body', function () {
const {body} = fetchMock.lastOptions()
const match = decodeURIComponent(body).match(/uri/gi)
const match = decodeURIComponent(JSON.stringify(body)).match(/uri/gi)
should(match).not.empty()
should(match).has.length(3, 'should have 3 uri params')
})

it('should contain 3 method=GET params in its body', function () {
const {body} = fetchMock.lastOptions()
const match = decodeURIComponent(body).match(/method=GET/gi)
const match = decodeURIComponent(JSON.stringify(body)).match(/method=GET/gi)
should(match).not.empty()
should(match).has.length(3, 'should have 3 method=GET params')
})
Expand Down
5 changes: 2 additions & 3 deletions test/integration/copy.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,15 @@
* limitations under the License.
*/

import * as fetchMock from 'fetch-mock'
import fetchMock from 'fetch-mock'
import should from 'should'
import {Api} from '../../src/Api'
import fixture from '../../fixtures/copy.json'

const API_URL = 'http://foobar:8080'

describe('Copy', function () {
afterEach(fetchMock.reset)
afterEach(fetchMock.restore)
afterEach(() => fetchMock.reset())

beforeEach(function () {
this.api = new Api({
Expand Down
5 changes: 2 additions & 3 deletions test/integration/count.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,15 @@
* limitations under the License.
*/

import * as fetchMock from 'fetch-mock'
import fetchMock from 'fetch-mock'
import should from 'should'
import {Api} from '../../src/Api'
import fixture from '../../fixtures/count.json'

const API_URL = 'http://foobar:8080'

describe('Count', function () {
afterEach(fetchMock.reset)
afterEach(fetchMock.restore)
afterEach(() => fetchMock.reset())

beforeEach(function () {
this.api = new Api({
Expand Down
5 changes: 2 additions & 3 deletions test/integration/create.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,15 @@
* limitations under the License.
*/

import * as fetchMock from 'fetch-mock'
import fetchMock from 'fetch-mock'
import should from 'should'
import {Api} from '../../src/Api'
import fixture from '../../fixtures/create.json'

const API_URL = 'http://foobar:8080'

describe('Create', function () {
afterEach(fetchMock.reset)
afterEach(fetchMock.restore)
afterEach(() => fetchMock.reset())

beforeEach(function () {
this.api = new Api({
Expand Down
7 changes: 3 additions & 4 deletions test/integration/edit.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,15 @@
* limitations under the License.
*/

import * as fetchMock from 'fetch-mock'
import fetchMock from 'fetch-mock'
import should from 'should'
import {Api} from '../../src/Api'
import fixture from '../../fixtures/edit.json'

const API_URL = 'http://foobar:8080'

describe('Edit', function () {
afterEach(fetchMock.reset)
afterEach(fetchMock.restore)
afterEach(() => fetchMock.reset())

beforeEach(function () {
this.api = new Api({
Expand Down Expand Up @@ -52,7 +51,7 @@ describe('Edit', function () {
const [url, opts] = fetchMock.lastCall('edit')
should(opts.method).equal('PUT')
should(url).endWith(objCode + '/' + objID)
should(opts.headers.get('apiKey')).equal('testapikey')
should((opts.headers as Headers).get('apiKey')).equal('testapikey')
should(opts.body).containEql(JSON.stringify(params))

should(data).have.properties(['ID', 'name', 'objCode'])
Expand Down
7 changes: 3 additions & 4 deletions test/integration/editUsingGet.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,15 @@
* limitations under the License.
*/

import * as fetchMock from 'fetch-mock'
import fetchMock from 'fetch-mock'
import should from 'should'
import {Api} from '../../src/Api'
import fixture from '../../fixtures/edit.json'

const API_URL = 'http://foobar:8080'

describe('Edit', function () {
afterEach(fetchMock.reset)
afterEach(fetchMock.restore)
afterEach(() => fetchMock.reset())

beforeEach(function () {
this.api = new Api({
Expand Down Expand Up @@ -53,7 +52,7 @@ describe('Edit', function () {
const [url, opts] = fetchMock.lastCall('edit')
should(opts.method).equal('GET')
should(url).containEql(objCode + '/' + objID)
should(opts.headers.get('apiKey')).equal('testapikey')
should((opts.headers as Headers).get('apiKey')).equal('testapikey')
should(opts.body).equal(null)
should(url).containEql('updates=' + encodeURIComponent(JSON.stringify(params)))
should(url).containEql('method=PUT')
Expand Down
5 changes: 2 additions & 3 deletions test/integration/execute.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,15 @@
* limitations under the License.
*/

import * as fetchMock from 'fetch-mock'
import fetchMock from 'fetch-mock'
import should from 'should'
import {Api} from '../../src/Api'
import fixture from '../../fixtures/execute.json'

const API_URL = 'http://foobar:8080'

describe('Execute', function () {
afterEach(fetchMock.reset)
afterEach(fetchMock.restore)
afterEach(() => fetchMock.reset())

beforeEach(function () {
this.api = new Api({
Expand Down
Loading

0 comments on commit dcb1cf5

Please sign in to comment.