Skip to content

Commit 73f49ff

Browse files
authored
refactor: migrate user-agent packages to TS (#1393)
* refactor: migrate user-agent packages to TS * fix: use ts-jest * fix: lint errors * fix: tests * fix: more lint errors * fix: more lint errors * chore: do not generate package-lock when installing packages for integration tests * refactor: use regex literal * refactor: to remove unnecessary assertion about meta dates
1 parent 770070a commit 73f49ff

File tree

184 files changed

+2166
-1618
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

184 files changed

+2166
-1618
lines changed

.eslintignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
credentials.js
12
coverage/*
23
**/coverage/*
34
dist/*
@@ -10,3 +11,4 @@ scripts/*
1011
**/scripts/*
1112
node_modules/*
1213
**/node_modules/*
14+
**/typescript-sdk/*

.prettierrc

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
{
22
"semi": false,
33
"trailingComma": "es5",
4-
"singleQuote": true
5-
}
4+
"singleQuote": true,
5+
"parser": "babel-flow",
6+
"overrides": [
7+
{
8+
"files": "*.ts",
9+
"options": {
10+
"parser": "typescript"
11+
}
12+
}
13+
]
14+
}

TODOS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@
66
| packages/product-json-to-csv/test/writer.spec.js | 263 | the "unzip" package fires finish event before entry events
77
| packages/product-json-to-csv/test/writer.spec.js | 308 | the "unzip" package fires finish event before entry events
88
| packages/sync-actions/src/utils/diffpatcher.js | 3 | create an issue here https://github.com/benjamine/jsondiffpatch/issues/new
9+
| /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

eslint-import-resolver-local.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* eslint-disable strict,no-param-reassign */
1+
/* eslint-disable import/no-extraneous-dependencies,strict,no-param-reassign */
22

33
// THIS FILE IS COPIED FROM jest
44
// https://github.com/facebook/jest/blob/master/eslintImportResolver.js

integration-tests/cli/csv-parser-orders.it.js

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -39,42 +39,42 @@ describe('CSV and CLI Tests', () => {
3939
})
4040

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

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

51-
it('on missing return-info headers', async () => {
51+
it('on missing return-info headers', () => {
5252
const csvFilePath = path.join(
5353
samplesFolder,
5454
'return-info-error2-sample.csv'
5555
)
5656
const jsonFilePath = tmp.fileSync().name
5757

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

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

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

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

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

@@ -148,16 +148,16 @@ describe('CSV and CLI Tests', () => {
148148
expect(data).toMatchSnapshot()
149149
})
150150

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

156-
expect(
156+
return expect(
157157
exec(
158158
`${binPath} -t deliveries --inputFile ${csvFilePath} --logFile ${tmpFile.name}`
159159
)
160-
).rejects.toThrowError(expectedError)
160+
).rejects.toThrow(expectedError)
161161
})
162162
})
163163
})

integration-tests/cli/csv-parser-price.it.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,13 @@ describe('CSV and CLI Tests', () => {
6060
})
6161

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

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

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

109109
const data = await fs.readFile(tmpFile.name, { encoding: 'utf8' })
110110
expect(data).toContain(expectedError)

integration-tests/cli/discount-codes.it.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,6 @@ describe('DiscountCode tests', () => {
195195
})
196196

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

@@ -261,8 +258,6 @@ describe('DiscountCode tests', () => {
261258
actual.forEach(codeObj => {
262259
expect(codeObj).toMatchObject(expected)
263260
expect(isuuid(codeObj.id)).toBe(true)
264-
expect(codeObj.createdAt).toMatch(UTCDateTimeRegex)
265-
expect(codeObj.lastModifiedAt).toMatch(UTCDateTimeRegex)
266261
})
267262
})
268263

integration-tests/cli/product-export.it.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ describe('Product Exporter', () => {
3939

4040
await expect(
4141
exec(`${bin} -o ${filePath} -p ${projectKey} --staged`)
42-
).rejects.toThrowError('No products found')
42+
).rejects.toThrow('No products found')
4343
})
4444
})
4545

integration-tests/cli/product-json-to-csv.it.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -512,8 +512,6 @@ describe('CSV and CLI Tests', () => {
512512
const fileNames = []
513513
let csvContents1 = ''
514514
let csvContents2 = ''
515-
let stdout
516-
let stderr
517515

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

788784
beforeAll(async () => {
789785
csvFile = tmp.fileSync({ postfix: '.csv' }).name

integration-tests/cli/product-json-to-xlsx.it.js

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,6 @@ function mapRowsToProducts(rows) {
4444
return _rows.map(row => zipObject(header, row))
4545
}
4646

47-
function analyzeExcelStream(stream) {
48-
const workbook = new Excel.Workbook()
49-
const readStream = workbook.xlsx.createInputStream()
50-
stream.pipe(readStream)
51-
52-
return new Promise((resolve, reject) => {
53-
readStream.on('error', reject)
54-
readStream.on('done', () => resolve(analyzeExcelWorkbook(workbook)))
55-
})
56-
}
57-
5847
function analyzeExcelWorkbook(workbook) {
5948
const rows = []
6049
const worksheet = workbook.getWorksheet('Products')
@@ -70,11 +59,22 @@ function analyzeExcelWorkbook(workbook) {
7059
}
7160
}
7261

73-
async function analyzeExcelFile(path) {
62+
function analyzeExcelStream(stream) {
63+
const workbook = new Excel.Workbook()
64+
const readStream = workbook.xlsx.createInputStream()
65+
stream.pipe(readStream)
66+
67+
return new Promise((resolve, reject) => {
68+
readStream.on('error', reject)
69+
readStream.on('done', () => resolve(analyzeExcelWorkbook(workbook)))
70+
})
71+
}
72+
73+
async function analyzeExcelFile(filePath) {
7474
const workbook = new Excel.Workbook()
75-
await workbook.xlsx.readFile(path)
75+
await workbook.xlsx.readFile(filePath)
7676
return {
77-
path,
77+
filePath,
7878
...(await analyzeExcelWorkbook(workbook)),
7979
}
8080
}
@@ -532,8 +532,6 @@ describe('XLSX and CLI Tests', () => {
532532
describe('WITHOUT HEADERS::should write products to `zip` file', () => {
533533
let product1
534534
let product2
535-
let stdout
536-
let stderr
537535
const fileNames = []
538536

539537
beforeAll(async done => {
@@ -791,8 +789,6 @@ describe('XLSX and CLI Tests', () => {
791789
let xlsxFile
792790
let excel
793791
let products
794-
let stdout
795-
let stderr
796792

797793
beforeAll(async () => {
798794
xlsxFile = tmp.fileSync({ postfix: '.xlsx' }).name

0 commit comments

Comments
 (0)