Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ scripts/*
**/scripts/*
node_modules/*
**/node_modules/*
**/typescript-sdk/*
13 changes: 11 additions & 2 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
{
"semi": false,
"trailingComma": "es5",
"singleQuote": true
}
"singleQuote": true,
"parser": "babel-flow",
"overrides": [
{
"files": "*.ts",
"options": {
"parser": "typescript"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we use the override feature to tell prettier to use typescript parser for the ts files, otherwise the babel-flow parser.

}
}
]
}
1 change: 1 addition & 0 deletions TODOS.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
| packages/product-json-to-csv/test/writer.spec.js | 263 | the "unzip" package fires finish event before entry events
| packages/product-json-to-csv/test/writer.spec.js | 308 | the "unzip" package fires finish event before entry events
| packages/sync-actions/src/utils/diffpatcher.js | 3 | create an issue here https://github.com/benjamine/jsondiffpatch/issues/new
| /Users/emmenko/dev/src/nodejs/packages/custom-objects-importer/src/main.js | 127 | remove `FlowFixMe` when [this](https://github.com/facebook/flow/issues/5294) issue is fixed
3 changes: 2 additions & 1 deletion jest.eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module.exports = {
runner: 'jest-runner-eslint',
displayName: 'eslint',
testMatch: ['<rootDir>/packages/**/*.js', '<rootDir>/packages/**/*.ts'],
modulePathIgnorePatterns: ['dist', 'lib'],
testMatch: ['<rootDir>/**/*.js', '<rootDir>/**/*.ts'],
}
11 changes: 10 additions & 1 deletion jest.test.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,19 @@ module.exports = {
'process.env': {
NODE_ENV: 'test',
},
// Without this option, somehow CI fails to run the tests with the following error:
// TypeError: Unable to require `.d.ts` file.
// This is usually the result of a faulty configuration or import. Make sure there is a `.js`, `.json` or another executable extension available alongside `core.ts`.
// Fix is based on this comment:
// - https://github.com/kulshekhar/ts-jest/issues/805#issuecomment-456055213
// - https://github.com/kulshekhar/ts-jest/blob/master/docs/user/config/isolatedModules.md
'ts-jest': {
isolatedModules: true,
},
},
transform: {
'^.+\\.js$': '<rootDir>/jest.transform.js',
'^.+\\.ts?$': '<rootDir>/node_modules/babel-jest',
'^.+\\.ts?$': 'ts-jest',
},
testRegex: '\\.spec\\.(js|ts)$',
moduleFileExtensions: ['ts', 'js'],
Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"lerna": "3.15.0",
"lerna": "3.16.4",
"version": "independent",
"useWorkspaces": true,
"npmclient": "yarn",
Expand Down
14 changes: 8 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"lint": "jest --projects jest.eslint.config.js jest.flow.config.js",
"lint:js": "jest --config jest.eslint.config.js",
"test": "cross-env NODE_ENV=development jest --config jest.test.config.js",
"test:watch": "yarn test --watch",
"test:package": "cross-env NODE_ENV=development ./scripts/test-package",
"pretest:integration": "./scripts/install-npm-packages-for-integration-tests",
"test:integration": "cross-env NODE_ENV=development jest --config integration-tests/jest.test.config.js",
Expand Down Expand Up @@ -74,16 +75,16 @@
"cross-env": "5.2.0",
"cz-lerna-changelog": "2.0.2",
"debug": "4.1.1",
"eslint": "6.0.1",
"eslint": "6.3.0",
"eslint-config-airbnb": "17.1.1",
"eslint-config-airbnb-base": "13.2.0",
"eslint-config-prettier": "6.0.0",
"eslint-formatter-pretty": "2.1.1",
"eslint-import-resolver-typescript": "1.1.1",
"eslint-plugin-babel": "5.3.0",
"eslint-plugin-flowtype": "3.11.1",
"eslint-plugin-flowtype": "4.3.0",
"eslint-plugin-import": "2.18.0",
"eslint-plugin-jest": "22.7.2",
"eslint-plugin-jest": "22.17.0",
"eslint-plugin-jsx-a11y": "6.2.3",
"eslint-plugin-prettier": "3.1.0",
"eslint-plugin-react": "7.14.2",
Expand All @@ -95,13 +96,13 @@
"gitbook-plugin-github": "3.0.0",
"gitbook-plugin-prism": "2.4.0",
"husky": "3.0.0",
"jest": "23.6.0",
"jest-each": "23.6.0",
"jest": "24.9.0",
"jest-each": "24.9.0",
"jest-runner-eslint": "0.7.4",
"jest-runner-flowtype": "0.0.7",
"jest-silent-reporter": "0.1.2",
"leasot": "7.5.0",
"lerna": "3.15.0",
"lerna": "3.16.4",
"lerna-changelog": "0.8.2",
"lint-staged": "9.1.0",
"npm-check-updates": "3.1.16",
Expand All @@ -120,6 +121,7 @@
"rollup-plugin-uglify": "6.0.2",
"rollup-watch": "4.3.1",
"streamtest": "1.2.4",
"ts-jest": "24.0.2",
"typescript": "3.5.3"
},
"config": {
Expand Down
2 changes: 1 addition & 1 deletion packages/api-request-builder/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"dist"
],
"scripts": {
"build": "cross-env yarn build:bundles",
"build": "yarn build:bundles",
"build:bundles": "cross-env NODE_ENV=production rollup -c ../../rollup.config.js -n CommercetoolsApiRequestBuilder -i ./src/index.js"
}
}
12 changes: 7 additions & 5 deletions packages/csv-parser-state/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export default class CsvParserState {
transitions,
...remainingState
}: StateWithUnresolvedTransitions): Promise<SuccessResult> {
return new Promise((resolve: Function) => {
return new Promise((resolve: Function, reject: Function) => {
if (!transitions) resolve(remainingState)
// We setup the client here because it is unnecessary
// if there are no transitions
Expand All @@ -125,17 +125,19 @@ export default class CsvParserState {
)
)
)
Promise.all(stateRequests).then(
(resolvedStates: Array<SuccessResult>) => {
Promise.all(stateRequests)
.then((resolvedStates: Array<SuccessResult>) => {
const stateReferences = resolvedStates.map(
(response: SuccessResult): StateReference => ({
typeId: 'state',
id: response.body.id,
})
)
resolve({ ...remainingState, transitions: stateReferences })
}
)
})
.catch((error: Error) => {
reject(error)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was missing. Somehow the tests caught this now

})
})
}

Expand Down
16 changes: 8 additions & 8 deletions packages/csv-parser-state/test/main.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,14 @@ describe('CsvParserState', () => {

describe('::_transformTransitions', () => {
describe('without state transitions', () => {
test('should not mutate state', async () => {
test('should not mutate state', () => {
const actual = {
foo: 'bar',
key: 'my-state',
}
expect(csvParser._transformTransitions(actual)).resolves.toEqual(actual)
return expect(csvParser._transformTransitions(actual)).resolves.toEqual(
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There were a bunch of tests that did not return the expectation with the promise.

actual
)
})
})

Expand Down Expand Up @@ -159,11 +161,10 @@ describe('CsvParserState', () => {
)
})

test('should resolve with modified state', () => {
test('should resolve with modified state', () =>
expect(
csvParser._transformTransitions(state)
).resolves.toMatchSnapshot()
})
).resolves.toMatchSnapshot())
})

describe('when execute rejects', () => {
Expand All @@ -173,11 +174,10 @@ describe('CsvParserState', () => {
)
})

test('should reject with execute rejection error', () => {
test('should reject with execute rejection error', () =>
expect(csvParser._transformTransitions(state)).rejects.toThrow(
/Invalid Request/
)
})
))
})
})
})
Expand Down
8 changes: 5 additions & 3 deletions packages/custom-objects-importer/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,10 @@ export default class CustomObjectsImporter {
return pSeries(functionsList).then((): Promise<void> => Promise.resolve())
}

_createPromiseReturningFunction(requests: Array<ClientRequest>): Function {
return async (): Promise<void> => {
_createPromiseReturningFunction(
requests: Array<ClientRequest>
): () => Promise<void> {
return async () => {
await Promise.all(
requests.map((request: ClientRequest): ExecutionResult =>
this._executeCreateOrUpdateAction(request)
Expand Down Expand Up @@ -289,7 +291,7 @@ export default class CustomObjectsImporter {
${unchangedCount} were unchanged.
`
if (createErrorCount || updateErrorCount) {
message += ` ${oneLine`
message += ` ${oneLine`
${createErrorCount + updateErrorCount} errors occurred
(${createErrorCount} create errors and
${updateErrorCount} update errors.)
Expand Down
23 changes: 11 additions & 12 deletions packages/custom-objects-importer/test/main.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,14 @@ describe('CustomObjectsImporter', () => {
objectsImport.client.execute = jest.fn()
})

test('should resolve', () => {
test('should resolve', async () => {
objectsImport.client.execute.mockReturnValue(
Promise.resolve({ body: { results: existingObjects } })
)

expect(objectsImport._processBatches(newObjects)).resolves.toBeTruthy()
return expect(
objectsImport._processBatches(newObjects)
).resolves.not.toThrow()
})
})

Expand All @@ -160,7 +162,7 @@ describe('CustomObjectsImporter', () => {
})
test('should run anonymous function', () => {
const func = objectsImport._createPromiseReturningFunction(requests)
expect(func()).resolves.toBe(undefined)
return expect(func()).resolves.toBe(undefined)
})
})

Expand All @@ -182,11 +184,10 @@ describe('CustomObjectsImporter', () => {
expect(objectsImport._summary.updatedCount).toBe(1)
})

test('should resolve promise', () => {
test('should resolve promise', () =>
expect(
objectsImport._executeCreateOrUpdateAction(createRequest)
).resolves.toBeUndefined()
})
).resolves.toBeUndefined())
})

describe('when error is thrown', () => {
Expand Down Expand Up @@ -217,11 +218,10 @@ describe('CustomObjectsImporter', () => {
expect(objectsImport._summary.updateErrorCount).toBe(1)
}))

test('should resolve promise', () => {
test('should resolve promise', () =>
expect(
objectsImport._executeCreateOrUpdateAction(createRequest)
).resolves.toBeUndefined()
})
).resolves.toBeUndefined())
})

describe('without `continueOnProblems`', () => {
Expand All @@ -240,11 +240,10 @@ describe('CustomObjectsImporter', () => {
expect(objectsImport._summary.updateErrorCount).toBe(1)
})

test('should reject promise', () => {
test('should reject promise', () =>
expect(
objectsImport._executeCreateOrUpdateAction(createRequest)
).rejects.toThrowErrorMatchingSnapshot()
})
).rejects.toThrowErrorMatchingSnapshot())
})
})
})
Expand Down
2 changes: 1 addition & 1 deletion packages/discount-code-importer/src/index.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export default from './main'
export { default } from './main'
41 changes: 41 additions & 0 deletions packages/http-user-agent/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
module.exports = {
parser: '@typescript-eslint/parser',
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned before, for now TS packages should have their own eslint config, which is merged with the base one.

Once we've migrated all packages, we can merge this back with the base one.

extends: [
'plugin:@typescript-eslint/recommended',
'plugin:import/typescript',
'plugin:jest/recommended',
'prettier',
'prettier/@typescript-eslint',
],
plugins: ['import', 'jest', 'prettier', '@typescript-eslint/eslint-plugin'],
env: {
es6: true,
browser: true,
jest: true,
node: true,
},
rules: {
'@typescript-eslint/camelcase': 0,
'@typescript-eslint/consistent-type-definitions': 0,
'@typescript-eslint/explicit-function-return-type': 0,
'@typescript-eslint/no-explicit-any': 2,
'@typescript-eslint/no-use-before-define': ['error', { functions: false }],
'@typescript-eslint/no-var-requires': 0,
'@typescript-eslint/unbound-method': 0,
'import/no-extraneous-dependencies': 0,
'import/no-named-as-default': 0,
'import/no-unresolved': 2,
},
settings: {
'import/parsers': {
'@typescript-eslint/parser': ['.ts'],
},
'import/resolver': {
'eslint-import-resolver-typescript': true,
typescript: {},
node: {
extensions: ['.js', '.ts'],
},
},
},
}
7 changes: 5 additions & 2 deletions packages/http-user-agent/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
"main": "dist/http-user-agent.cjs.js",
"module": "dist/http-user-agent.es.js",
"browser": "dist/http-user-agent.umd.js",
"typings": "./dist/typings/index.d.ts",
"types": "./dist/typings/index.d.ts",
"repository": {
"type": "git",
"url": "https://github.com/commercetools/nodejs.git"
Expand All @@ -27,7 +29,8 @@
],
"scripts": {
"prebuild": "rimraf dist/**",
"build": "cross-env yarn build:bundles",
"build:bundles": "cross-env NODE_ENV=production rollup -c ../../rollup.config.js -n CommercetoolsHttpUserAgent -i ./src/index.js"
"build": "yarn build:bundles && yarn build:typings",
"build:bundles": "cross-env NODE_ENV=production rollup -c ../../rollup.config.js -n CommercetoolsHttpUserAgent -i ./src/index.ts",
"build:typings": "tsc -p tsconfig.declarations.json --emitDeclarationOnly --declarationDir dist/typings"
}
}
Loading