Skip to content
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 .eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
credentials.js
coverage/*
**/coverage/*
dist/*
Expand All @@ -10,3 +11,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
2 changes: 1 addition & 1 deletion eslint-import-resolver-local.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint-disable strict,no-param-reassign */
/* eslint-disable import/no-extraneous-dependencies,strict,no-param-reassign */

// THIS FILE IS COPIED FROM jest
// https://github.com/facebook/jest/blob/master/eslintImportResolver.js
Expand Down
30 changes: 15 additions & 15 deletions integration-tests/cli/csv-parser-orders.it.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,42 +39,42 @@ describe('CSV and CLI Tests', () => {
})

describe('CLI logs specific errors', () => {
it('on faulty CSV format', async () => {
it('on faulty CSV format', () => {
const csvFilePath = path.join(samplesFolder, 'faulty-sample.csv')
const jsonFilePath = tmp.fileSync().name

expect(
return expect(
exec(`${binPath} -i ${csvFilePath} -o ${jsonFilePath} -t returninfo`)
).rejects.toThrowError(/Row length does not match headers/)
).rejects.toThrow(/Row length does not match headers/)
})

it('on missing return-info headers', async () => {
it('on missing return-info headers', () => {
const csvFilePath = path.join(
samplesFolder,
'return-info-error2-sample.csv'
)
const jsonFilePath = tmp.fileSync().name

expect(
return expect(
exec(`${binPath} -i ${csvFilePath} -o ${jsonFilePath} -t returninfo`)
).rejects.toThrowError(/Required headers missing: 'orderNumber'/)
).rejects.toThrow(/Required headers missing: 'orderNumber'/)
})

it('on missing line-item-state headers', async () => {
it('on missing line-item-state headers', () => {
const csvFilePath = path.join(samplesFolder, 'return-info-sample.csv')
const jsonFilePath = tmp.fileSync().name

expect(
return expect(
exec(`${binPath} -i ${csvFilePath} -o ${jsonFilePath} -t lineitemstate`)
).rejects.toThrowError(/Required headers missing: 'fromState,toState'/)
).rejects.toThrow(/Required headers missing: 'fromState,toState'/)
})

it('stack trace on verbose level', async () => {
it('stack trace on verbose level', () => {
const csvFilePath = path.join(samplesFolder, 'faulty-sample.csv')

expect(
return expect(
exec(`${binPath} -i ${csvFilePath} --logLevel verbose -t returninfo`)
).rejects.toThrowError(/ERR: Row length does not match headers/)
).rejects.toThrow(/ERR: Row length does not match headers/)
})
})

Expand Down Expand Up @@ -148,16 +148,16 @@ describe('CSV and CLI Tests', () => {
expect(data).toMatchSnapshot()
})

it('CLI should log errors to stderr and log file', async () => {
it('CLI should log errors to stderr and log file', () => {
const tmpFile = tmp.fileSync()
const expectedError = 'Row length does not match headers'
const csvFilePath = path.join(samplesFolder, 'faulty-sample.csv')

expect(
return expect(
exec(
`${binPath} -t deliveries --inputFile ${csvFilePath} --logFile ${tmpFile.name}`
)
).rejects.toThrowError(expectedError)
).rejects.toThrow(expectedError)
})
})
})
8 changes: 4 additions & 4 deletions integration-tests/cli/csv-parser-price.it.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ describe('CSV and CLI Tests', () => {
})

describe('CLI logs specific errors', () => {
it('on faulty CSV format', async () => {
it('on faulty CSV format', () => {
const csvFilePath = path.join(samplesFolder, 'faulty-sample.csv')
const jsonFilePath = tmp.fileSync().name

expect(
return expect(
exec(`${binPath} -p ${projectKey} -i ${csvFilePath} -o ${jsonFilePath}`)
).rejects.toThrowError(/Row length does not match headers/)
).rejects.toThrow(/Row length does not match headers/)
})

it('on parsing errors', async () => {
Expand Down Expand Up @@ -104,7 +104,7 @@ describe('CSV and CLI Tests', () => {
exec(
`${binPath} -p ${projectKey} -i ${csvFilePath} --logFile ${tmpFile.name}`
)
).rejects.toThrowError(expectedError)
).rejects.toThrow(expectedError)

const data = await fs.readFile(tmpFile.name, { encoding: 'utf8' })
expect(data).toContain(expectedError)
Expand Down
5 changes: 0 additions & 5 deletions integration-tests/cli/discount-codes.it.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,6 @@ describe('DiscountCode tests', () => {
})

describe('Discount Code Exporter', () => {
const UTCDateTimeRegex = new RegExp(
/[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}.[0-9]{3}Z/g
)
let preparedDiscountCodes
const bin = './integration-tests/node_modules/.bin/discount-code-exporter'

Expand Down Expand Up @@ -261,8 +258,6 @@ describe('DiscountCode tests', () => {
actual.forEach(codeObj => {
expect(codeObj).toMatchObject(expected)
expect(isuuid(codeObj.id)).toBe(true)
expect(codeObj.createdAt).toMatch(UTCDateTimeRegex)
expect(codeObj.lastModifiedAt).toMatch(UTCDateTimeRegex)
})
})

Expand Down
2 changes: 1 addition & 1 deletion integration-tests/cli/product-export.it.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe('Product Exporter', () => {

await expect(
exec(`${bin} -o ${filePath} -p ${projectKey} --staged`)
).rejects.toThrowError('No products found')
).rejects.toThrow('No products found')
})
})

Expand Down
4 changes: 0 additions & 4 deletions integration-tests/cli/product-json-to-csv.it.js
Original file line number Diff line number Diff line change
Expand Up @@ -512,8 +512,6 @@ describe('CSV and CLI Tests', () => {
const fileNames = []
let csvContents1 = ''
let csvContents2 = ''
let stdout
let stderr

beforeAll(async done => {
const zipFile = tmp.fileSync({ postfix: '.zip' }).name
Expand Down Expand Up @@ -782,8 +780,6 @@ describe('CSV and CLI Tests', () => {
const templateFile = `${__dirname}/helpers/product-headers.csv`
let csvFile
let products = []
let stdout
let stderr

beforeAll(async () => {
csvFile = tmp.fileSync({ postfix: '.csv' }).name
Expand Down
32 changes: 14 additions & 18 deletions integration-tests/cli/product-json-to-xlsx.it.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,6 @@ function mapRowsToProducts(rows) {
return _rows.map(row => zipObject(header, row))
}

function analyzeExcelStream(stream) {
const workbook = new Excel.Workbook()
const readStream = workbook.xlsx.createInputStream()
stream.pipe(readStream)

return new Promise((resolve, reject) => {
readStream.on('error', reject)
readStream.on('done', () => resolve(analyzeExcelWorkbook(workbook)))
})
}

function analyzeExcelWorkbook(workbook) {
const rows = []
const worksheet = workbook.getWorksheet('Products')
Expand All @@ -70,11 +59,22 @@ function analyzeExcelWorkbook(workbook) {
}
}

async function analyzeExcelFile(path) {
function analyzeExcelStream(stream) {
const workbook = new Excel.Workbook()
const readStream = workbook.xlsx.createInputStream()
stream.pipe(readStream)

return new Promise((resolve, reject) => {
readStream.on('error', reject)
readStream.on('done', () => resolve(analyzeExcelWorkbook(workbook)))
})
}

async function analyzeExcelFile(filePath) {
const workbook = new Excel.Workbook()
await workbook.xlsx.readFile(path)
await workbook.xlsx.readFile(filePath)
return {
path,
filePath,
...(await analyzeExcelWorkbook(workbook)),
}
}
Expand Down Expand Up @@ -532,8 +532,6 @@ describe('XLSX and CLI Tests', () => {
describe('WITHOUT HEADERS::should write products to `zip` file', () => {
let product1
let product2
let stdout
let stderr
const fileNames = []

beforeAll(async done => {
Expand Down Expand Up @@ -791,8 +789,6 @@ describe('XLSX and CLI Tests', () => {
let xlsxFile
let excel
let products
let stdout
let stderr

beforeAll(async () => {
xlsxFile = tmp.fileSync({ postfix: '.xlsx' }).name
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/cli/resource-deleter.it.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { getCredentials } from '@commercetools/get-credentials'
import { exec } from 'mz/child_process'
import { version } from '@commercetools/resource-deleter/package.json'
import * as resources from './helpers/resource-delete.data'
import { logger } from '../../packages/resource-deleter/src/utils/silent-logger'
import logger from '../../packages/resource-deleter/src/utils/silent-logger'
import { createData, clearData } from './helpers/utils'

const projectKey =
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/sdk/channels.it.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { createQueueMiddleware } from '@commercetools/sdk-middleware-queue'
import { createUserAgentMiddleware } from '@commercetools/sdk-middleware-user-agent'
import omit from 'lodash.omit'
import fetch from 'node-fetch'
import { clearData } from './../cli/helpers/utils'
import { clearData } from '../cli/helpers/utils'
import pkg from '../package.json'

let projectKey
Expand Down
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
1 change: 1 addition & 0 deletions jest.transform.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const babelConfig = require('./babel.config')

// eslint-disable-next-line import/no-extraneous-dependencies
module.exports = require('babel-jest').createTransformer(babelConfig)
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"
}
}
Loading