Skip to content

Commit

Permalink
build(deps-dev): update eslint, typescript-eslint and fix lint issues (
Browse files Browse the repository at this point in the history
  • Loading branch information
ahnpnl committed May 22, 2020
1 parent 558c307 commit 49d5e0e
Show file tree
Hide file tree
Showing 29 changed files with 1,885 additions and 1,379 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ e2e/__external-repos__/
coverage/
docs/
*.config.js
.eslintrc.js
8 changes: 6 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ module.exports = {
},
plugins: ['@typescript-eslint', 'jest', 'jsdoc'],
rules: {
'prettier/prettier': 'error',
'prettier/prettier': 'error',
'no-unused-vars': 'off', // let typescript-eslint handle this
'no-console': 'error',
'linebreak-style': 'off',
Expand Down Expand Up @@ -120,7 +120,6 @@ module.exports = {
},
},
],
'@typescript-eslint/class-name-casing': 'error',
'@typescript-eslint/prefer-regexp-exec': 'warn',
'@typescript-eslint/prefer-string-starts-ends-with': 'warn',
'@typescript-eslint/unbound-method': 'off',
Expand Down Expand Up @@ -159,9 +158,14 @@ module.exports = {
'@typescript-eslint/no-namespace': 'warn',
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/no-parameter-properties': 'off',
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/no-unsafe-call': 'off',
'@typescript-eslint/no-unsafe-member-access': 'off',
'@typescript-eslint/no-unsafe-return': 'off',
'@typescript-eslint/no-unnecessary-boolean-literal-compare': 'error',
'@typescript-eslint/no-use-before-define': 'off',
'@typescript-eslint/no-var-requires': 'off',
'@typescript-eslint/restrict-template-expressions': 'off',
'@typescript-eslint/prefer-for-of': 'off',
'@typescript-eslint/prefer-function-type': 'error',
'@typescript-eslint/prefer-namespace-keyword': 'error',
Expand Down
17 changes: 12 additions & 5 deletions e2e/__helpers__/test-case/run-descriptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,23 @@ export default class RunDescriptor {
this._options = { ...options }
}

get sourceDir() {
get sourceDir(): string {
return join(Paths.e2eSourceDir, this.name)
}
get templateWorkdir() {

get templateWorkdir(): string {
return join(Paths.e2eWorkTemplatesDir, this.name)
}
get workdir() {

get workdir(): string {
return join(Paths.e2eWorkDir, this.templateName, this.name)
}

get sourcePackageJson() {
get sourcePackageJson(): any {
try {
return this._sourcePackageJson || (this._sourcePackageJson = require(join(this.sourceDir, 'package.json')))
} catch (err) {}

return {}
}

Expand All @@ -36,6 +39,7 @@ export default class RunDescriptor {
// read the template from the package field if it is not given
this._options.template = this.sourcePackageJson.e2eTemplate || 'default'
}

return this._options.template as string
}

Expand All @@ -59,6 +63,7 @@ export default class RunDescriptor {
'\n',
)
}

return result
}

Expand All @@ -70,10 +75,10 @@ export default class RunDescriptor {
if (templates.length < 1) {
throw new RangeError(`There must be at least one template to run the test case with.`)
}

if (!templates.every((t, i) => !templates.includes(t, i + 1))) {
throw new Error(`Each template must be unique. Given ${templates.join(', ')}`)
}

return templates.reduce((map, template) => {
const desc = new RunDescriptor(this.name, {
...this._options,
Expand All @@ -85,6 +90,7 @@ export default class RunDescriptor {
} else {
runTest()
}

return map
}, {} as TestRunResultsMap<T>)
}
Expand All @@ -97,6 +103,7 @@ function createIteratorContext(templateName: string, expectedStatus?: number): R
}
return status === 0 ? 'pass' : 'fail'
}

return {
templateName,
describeLabel: `with template "${templateName}"`,
Expand Down
38 changes: 26 additions & 12 deletions e2e/__helpers__/test-case/run-result.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,50 +23,63 @@ export default class RunResult {
digest: string
}>,
) {}
get logFilePath() {

get logFilePath(): string {
return resolve(this.cwd, 'ts-jest.log')
}
get logFileContent() {

get logFileContent(): string {
return readFileSync(this.logFilePath).toString('utf8')
}

get logFileEntries(): LogMessage[] {
const lines = this.logFileContent.split(/\n/g)
// remove last, empty line
lines.pop()
return lines.map(s => JSON.parse(s))
}
get isPass() {

get isPass(): boolean {
return this.status === 0
}
get isFail() {

get isFail(): boolean {
return !this.isPass
}
get status() {

get status(): number | null {
return this.result.status
}
get output() {

get output(): string {
return this.normalize(stripAnsiColors(this.result.output ? this.result.output.join('\n\n') : ''))
}
get stderr() {

get stderr(): string {
return this.normalize(stripAnsiColors((this.result.stderr || '').toString()))
}
get normalizedStderr() {

get normalizedStderr(): string {
return normalizeJestOutput(this.stderr)
}
get stdout() {

get stdout(): string {
return this.normalize(stripAnsiColors((this.result.stdout || '').toString()))
}
get normalizedStdout() {

get normalizedStdout(): string {
return normalizeJestOutput(this.stdout)
}
get cmdLine() {

get cmdLine(): string {
const args = [this.context.cmd, ...this.context.args].filter(
a => !['-u', '--updateSnapshot', '--runInBand', '--'].includes(a),
)
const configIndex = args.indexOf('--config')
if (configIndex !== -1) {
args.splice(configIndex, 2)
}

return this.normalize(args.join(' '))
}

Expand All @@ -80,10 +93,11 @@ export default class RunResult {
} catch (err) {
io.out = `/*\nts-jest after hook has not been called!\n${err}\noutput:\n${this.output}*/`
}

return new ProcessedFileIo(this.cwd, relFilePath, io.in, io.out)
}

normalize(str: string) {
normalize(str: string): string {
// TODO: clean this!
const cwd = this.cwd
const realCwd = realpathSync(cwd)
Expand Down
2 changes: 1 addition & 1 deletion e2e/__helpers__/test-case/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import RunResult from './run-result'

export interface RunTestOptions {
template?: string
env?: {}
env?: Record<string, unknown>
inject?: (() => any) | string
writeIo?: boolean
jestConfig?: Config.ProjectConfig | any
Expand Down
4 changes: 2 additions & 2 deletions e2e/__helpers__/test-case/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ export function normalizeJestOutput(output: string): string {
return out
}

export function escapeRegex(s: string) {
export function escapeRegex(s: string): string {
// eslint-disable-next-line no-useless-escape
return s.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&')
}

export function enableOptimizations() {
export function enableOptimizations(): boolean {
return !!process.env.TS_JEST_E2E_OPTIMIZATIONS
}
29 changes: 15 additions & 14 deletions e2e/__serializers__/run-result.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import RunResult from '../__helpers__/test-case/run-result'

export const test = (val: any) => val && val instanceof RunResult
export const print = (val: RunResult, _: any, indent: any) => {
const out = [
`${val.status === 0 ? '√' : '×'} ${val.cmdLine}`,
`↳ exit code: ${val.status}`,
`===[ STDOUT ]${'='.repeat(67)}`,
val.normalizedStdout,
`===[ STDERR ]${'='.repeat(67)}`,
val.normalizedStderr,
'='.repeat(80),
]
.map(l => indent(l))
.join('\n')
return out
export const test = (val: unknown): boolean => val && val instanceof RunResult
export const print = (val: RunResult, _: unknown, indent: (l: string) => unknown): string => {
const out = [
`${ val.status === 0 ? '√' : '×' } ${ val.cmdLine }`,
`↳ exit code: ${ val.status }`,
`===[ STDOUT ]${ '='.repeat(67) }`,
val.normalizedStdout,
`===[ STDERR ]${ '='.repeat(67) }`,
val.normalizedStderr,
'='.repeat(80),
]
.map(l => indent(l))
.join('\n')

return out
}
2 changes: 1 addition & 1 deletion e2e/__tests__/module-kinds/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const runTestForOptions = (options: {
module: string
allowSyntheticDefaultImports?: boolean
esModuleInterop?: boolean
}) => {
}): void => {
test(`run with options: ${JSON.stringify(options)}`, () => {
expect(testCaseForCompilerOpt(options).run()).toMatchSnapshot()
})
Expand Down
Loading

0 comments on commit 49d5e0e

Please sign in to comment.