Skip to content

Commit

Permalink
feat(ts): init project with typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
tduyng committed Dec 13, 2021
1 parent 0ba3d68 commit 51156b3
Show file tree
Hide file tree
Showing 9 changed files with 1,845 additions and 1,571 deletions.
356 changes: 321 additions & 35 deletions .yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
plugins:
- path: .yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs
spec: "@yarnpkg/plugin-interactive-tools"

yarnPath: .yarn/releases/yarn-3.1.0.cjs
10 changes: 9 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
module.exports = {
coveragePathIgnorePatterns: ['/node_modules/', '/tests/'],
preset: 'ts-jest',
testEnvironment: 'node',
clearMocks: true,
moduleFileExtensions: ['js', 'ts'],
testRegex: '.*\\.test\\.(t|j)s$',
transform: {
'^.+\\.(t|j)s$': 'ts-jest',
},
coverageDirectory: './coverage',
}
36 changes: 20 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,36 +31,40 @@
"dependencies": {
"arg": "5.0.1",
"chai": "4.3",
"fs-extra": "10.0",
"glob": "7.1",
"jest-diff": "27.0",
"js-yaml": "4.1",
"lodash": "4.17",
"moment-timezone": "0.5.33",
"natural-compare": "1.4",
"pretty-format": "27.0",
"request": "2.88",
"tough-cookie": "4.0"
"fs-extra": "10.0.0",
"glob": "7.2.0",
"jest-diff": "27.4.2",
"js-yaml": "4.1.0",
"lodash": "4.17.21",
"moment-timezone": "0.5.34",
"natural-compare": "1.4.0",
"pretty-format": "27.4.2",
"request": "2.88.2",
"tough-cookie": "4.0.0"
},
"devDependencies": {
"@commitlint/config-conventional": "12.x",
"@commitlint/config-conventional": "15.x",
"@cucumber/cucumber": "7.x",
"@types/jest": "27.x",
"@types/node": "16.x",
"babylon": "6.x",
"chalk": "4.x",
"commitlint": "12.x",
"commitlint": "15.x",
"conventional-changelog-cli": "2.x",
"coveralls": "3.x",
"eslint": "7.x",
"eslint": "8.x",
"gh-pages": "3.x",
"husky": "7.x",
"husky": "^7.0.4",
"jest": "27.x",
"jsdoc": "3.x",
"lint-staged": "11.x",
"lint-staged": "12.x",
"minami": "1.x",
"mustache": "4.x",
"nock": "13.x",
"prettier": "2.x",
"sinon": "11.x"
"sinon": "12.x",
"ts-jest": "27.x",
"typescript": "4.5.x"
},
"peerDependencies": {
"@cucumber/cucumber": ">=7.0.0"
Expand Down
12 changes: 6 additions & 6 deletions src/extensions/cli/definitions.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ exports.install = () => {
this.cli.setCwd(cwd)
})

Given(/^(?:I )?set ([^ ]+) (?:env|environment) (?:var|variable) to (.+)$/, function (
name,
value
) {
this.cli.setEnvironmentVariable(name, value)
})
Given(
/^(?:I )?set ([^ ]+) (?:env|environment) (?:var|variable) to (.+)$/,
function (name, value) {
this.cli.setEnvironmentVariable(name, value)
}
)

Given(/^(?:I )?set (?:env|environment) (?:vars|variables)$/, function (step) {
this.cli.setEnvironmentVariables(step.rowsHash())
Expand Down
57 changes: 28 additions & 29 deletions src/extensions/file_system/definitions.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,35 +39,34 @@ exports.install = () => {
/**
* Checking file content.
*/
Then(/^file (.+) content should (not )?(equal|contain|match) (.+)$/, function (
file,
flag,
comparator,
expectedValue
) {
return this.fileSystem
.getFileContent(this.cli.getCwd(), file)
.then((content) => {
let expectFn = expect(
content,
`Expected file '${file}' to ${
flag ? flag : ''
}${comparator} '${expectedValue}', but found '${content}' which does${
flag ? '' : ' not'
}`
).to
if (flag != undefined) {
expectFn = expectFn.not
}
Then(
/^file (.+) content should (not )?(equal|contain|match) (.+)$/,
function (file, flag, comparator, expectedValue) {
return this.fileSystem
.getFileContent(this.cli.getCwd(), file)
.then((content) => {
let expectFn = expect(
content,
`Expected file '${file}' to ${
flag ? flag : ''
}${comparator} '${expectedValue}', but found '${content}' which does${
flag ? '' : ' not'
}`
).to
if (flag != undefined) {
expectFn = expectFn.not
}

expectFn[comparator](
comparator === 'match' ? new RegExp(expectedValue) : expectedValue
)
})
.catch((err) => {
if (err.code === 'ENOENT') return expect.fail('', '', `File '${file}' should exist`)
expectFn[comparator](
comparator === 'match' ? new RegExp(expectedValue) : expectedValue
)
})
.catch((err) => {
if (err.code === 'ENOENT')
return expect.fail('', '', `File '${file}' should exist`)

return Promise.reject(err)
})
})
return Promise.reject(err)
})
}
)
}
62 changes: 30 additions & 32 deletions src/extensions/http_api/definitions.js
Original file line number Diff line number Diff line change
Expand Up @@ -318,17 +318,17 @@ exports.install = ({ baseUrl = '' } = {}) => {
/**
* This definition verify that an array for a given path has the expected length
*/
Then(/^(?:I )?should receive a collection of ([0-9]+) items?(?: for path )?(.+)?$/, function (
size,
path
) {
const response = mustGetResponse(this.httpApiClient)
const { body } = response
Then(
/^(?:I )?should receive a collection of ([0-9]+) items?(?: for path )?(.+)?$/,
function (size, path) {
const response = mustGetResponse(this.httpApiClient)
const { body } = response

const array = path != undefined ? _.get(body, path) : body
const array = path != undefined ? _.get(body, path) : body

expect(array.length).to.be.equal(Number(size))
})
expect(array.length).to.be.equal(Number(size))
}
)

/**
* Verifies that response matches a fixture.
Expand All @@ -344,28 +344,26 @@ exports.install = ({ baseUrl = '' } = {}) => {
/**
* Checking response header.
*/
Then(/^response header (.+) should (not )?(equal|contain|match) (.+)$/, function (
key,
flag,
comparator,
expectedValue
) {
const response = mustGetResponse(this.httpApiClient)
const header = response.headers[key.toLowerCase()]

expect(header, `Header '${key}' does not exist`).to.not.be.undefined

let expectFn = expect(
header,
`Expected header '${key}' to ${
flag ? flag : ''
}${comparator} '${expectedValue}', but found '${header}' which does${
flag ? '' : ' not'
}`
).to
if (flag != undefined) {
expectFn = expectFn.not
Then(
/^response header (.+) should (not )?(equal|contain|match) (.+)$/,
function (key, flag, comparator, expectedValue) {
const response = mustGetResponse(this.httpApiClient)
const header = response.headers[key.toLowerCase()]

expect(header, `Header '${key}' does not exist`).to.not.be.undefined

let expectFn = expect(
header,
`Expected header '${key}' to ${
flag ? flag : ''
}${comparator} '${expectedValue}', but found '${header}' which does${
flag ? '' : ' not'
}`
).to
if (flag != undefined) {
expectFn = expectFn.not
}
expectFn[comparator](comparator === 'match' ? new RegExp(expectedValue) : expectedValue)
}
expectFn[comparator](comparator === 'match' ? new RegExp(expectedValue) : expectedValue)
})
)
}
25 changes: 25 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@


{
"compilerOptions": {
"incremental": true,
"noImplicitAny": true,
"outDir": "./build",
"allowJs": true,
"target": "es2019",
"module": "commonjs",
"lib": ["es2020"],
"alwaysStrict": true,
"sourceMap": true,
"skipLibCheck": true,
"noUnusedParameters": false,
"noUnusedLocals": false,
"strictNullChecks": true,
"noUncheckedIndexedAccess": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"forceConsistentCasingInFileNames": true,
},
"includes": ["**/*"],
"exclude": ["./node_modules", "./build", "./coverage"]
}
Loading

0 comments on commit 51156b3

Please sign in to comment.