Skip to content

Commit

Permalink
Merge branch 'fix-module-warning' into testMatch-and-testRegex
Browse files Browse the repository at this point in the history
  • Loading branch information
huafu committed Sep 24, 2018
2 parents 31ad0aa + 9e7d2f0 commit e317e3b
Show file tree
Hide file tree
Showing 35 changed files with 1,415 additions and 103 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
@@ -1,7 +1,7 @@
language: node_js

env:
- TS_JEST_E2E_WORKDIR=/tmp/ts-jest-e2e-workdir
- TS_JEST_E2E_WORKDIR=/tmp/ts-jest-e2e-workdir TS_JEST_E2E_OPTIMIZATIONS=1

cache:
npm: true
Expand Down
1 change: 1 addition & 0 deletions appveyor.yml
Expand Up @@ -24,6 +24,7 @@ install:
# - set CI=true
# Our E2E work dir
- set TS_JEST_E2E_WORKDIR=%APPDATA%\ts-jest-e2e
- set TS_JEST_E2E_OPTIMIZATIONS=1
- npm ci --ignore-scripts
- npm run clean -- --when-ci-commit-message

Expand Down
7 changes: 7 additions & 0 deletions e2e/__cases__/module-kinds/import-default.spec.ts
@@ -0,0 +1,7 @@
import lib from './lib'

test('import default', () => {
expect(typeof lib).toBe('function')
expect(lib()).toBe('foo')
expect(lib.bar).toBe('bar')
})
7 changes: 7 additions & 0 deletions e2e/__cases__/module-kinds/import-legacy.spec.ts
@@ -0,0 +1,7 @@
import lib = require('./lib')

test('import default', () => {
expect(typeof lib).toBe('function')
expect(lib()).toBe('foo')
expect(lib.bar).toBe('bar')
})
7 changes: 7 additions & 0 deletions e2e/__cases__/module-kinds/import-star.spec.ts
@@ -0,0 +1,7 @@
import * as lib from './lib'

test('import default', () => {
expect(typeof lib).toBe('function')
expect(lib()).toBe('foo')
expect(lib.bar).toBe('bar')
})
5 changes: 5 additions & 0 deletions e2e/__cases__/module-kinds/lib.d.ts
@@ -0,0 +1,5 @@
declare function lib ()
declare namespace lib {
export const bar: string
}
export = lib
5 changes: 5 additions & 0 deletions e2e/__cases__/module-kinds/lib.js
@@ -0,0 +1,5 @@
function lib() { return 'foo' }

lib.bar = 'bar'

module.exports = lib
8 changes: 8 additions & 0 deletions e2e/__cases__/module-kinds/tsconfig.json
@@ -0,0 +1,8 @@
{
"compilerOptions": {
"target": "es5",
"allowJs": true,
"rootDir": ".",
"outDir": "dist"
}
}
4 changes: 2 additions & 2 deletions e2e/__helpers__/test-case/__hooks-source__.js.hbs
Expand Up @@ -3,13 +3,13 @@
const fs = require('fs')
const path = require('path')
const root = __dirname
const writeProcessIoTo = {{writeProcessIoTo}}
const writeProcessIoTo = path.resolve(root, {{writeProcessIoTo}})

exports.afterProcess = function (args, result) {
// const source = args[0]
const filePath = args[1]
const relPath = path.relative(root, filePath)
if (writeProcessIoTo && filePath.startsWith(`${root}${path.sep}`)) {
if (filePath.startsWith(`${root}${path.sep}`)) {
const dest = `${path.join(writeProcessIoTo, relPath)}.json`
const segments = relPath.split(path.sep)
segments.pop()
Expand Down
17 changes: 15 additions & 2 deletions e2e/__helpers__/test-case/run-descriptor.ts
Expand Up @@ -26,7 +26,10 @@ export default class RunDescriptor {
}

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

get templateName(): string {
Expand All @@ -45,8 +48,18 @@ export default class RunDescriptor {
if (logUnlessStatus != null && logUnlessStatus !== result.status) {
// tslint:disable-next-line:no-console
console.log(
`Output of test run in "${this.name}" using template "${this.templateName}" (exit code: ${result.status}):\n\n`,
'='.repeat(70),
'\n',
`Test exited with unexpected status in "${this.name}" using template "${this.templateName}" (exit code: ${
result.status
}):\n`,
result.context.cmd,
result.context.args.join(' '),
'\n\n',
result.output.trim(),
'\n',
'='.repeat(70),
'\n',
)
}
return result
Expand Down
18 changes: 11 additions & 7 deletions e2e/__helpers__/test-case/run-result.ts
Expand Up @@ -20,6 +20,7 @@ export default class RunResult {
args: string[]
env: { [key: string]: string }
config: jest.InitialOptions
digest: string
}>,
) {}
get logFilePath() {
Expand All @@ -44,26 +45,29 @@ export default class RunResult {
return this.result.status
}
get output() {
return stripAnsiColors(this.result.output ? this.result.output.join('\n\n') : '')
return this.normalize(stripAnsiColors(this.result.output ? this.result.output.join('\n\n') : ''))
}
get stderr() {
return stripAnsiColors((this.result.stderr || '').toString())
return this.normalize(stripAnsiColors((this.result.stderr || '').toString()))
}
get normalizedStderr() {
return normalizeJestOutput(this.stderr)
}
get stdout() {
return stripAnsiColors((this.result.stdout || '').toString())
return this.normalize(stripAnsiColors((this.result.stdout || '').toString()))
}
get normalizedStdout() {
return normalizeJestOutput(this.stdout)
}
get cmdLine() {
return this.normalize(
[this.context.cmd, ...this.context.args]
.filter(a => !['-u', '--updateSnapshot', '--runInBand', '--'].includes(a))
.join(' '),
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(' '))
}

ioFor(relFilePath: string): ProcessedFileIo {
Expand Down

0 comments on commit e317e3b

Please sign in to comment.