Skip to content

Commit

Permalink
test(e2e): deep paths and coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
huafu committed Sep 20, 2018
1 parent 6ccbff3 commit 0141098
Show file tree
Hide file tree
Showing 12 changed files with 366 additions and 0 deletions.
5 changes: 5 additions & 0 deletions e2e/__cases__/deep/package.json
@@ -0,0 +1,5 @@
{
"scripts": {
"test": "cd src/Tests && jest"
}
}
5 changes: 5 additions & 0 deletions e2e/__cases__/deep/src/Button/click.ts
@@ -0,0 +1,5 @@
import * as mod from './mod'

export function click(foo: string) {
return `clicked ${mod(foo)}`
}
3 changes: 3 additions & 0 deletions e2e/__cases__/deep/src/Button/mod.d.ts
@@ -0,0 +1,3 @@
type ModExport = (str: string) => string
declare const _export: ModExport
export = _export
3 changes: 3 additions & 0 deletions e2e/__cases__/deep/src/Button/mod.js
@@ -0,0 +1,3 @@
module.exports = function(str) {
return str.toUpperCase()
}
5 changes: 5 additions & 0 deletions e2e/__cases__/deep/src/Tests/Button/click.test.ts
@@ -0,0 +1,5 @@
import { click } from '../../Button/click'

test('button should click!', () => {
expect(click('bar')).toBe('clicked BAR')
})
24 changes: 24 additions & 0 deletions e2e/__cases__/deep/src/Tests/jest.config.js
@@ -0,0 +1,24 @@
const cfg = {}

if (require('jest/package.json').version.split('.').shift() === '22') {
Object.assign(cfg, require('ts-jest').jestPreset)
} else {
cfg.preset = 'ts-jest'
}

module.exports = Object.assign({}, cfg, {
collectCoverage: true,
collectCoverageFrom: ["**/*.ts", "!**/*.d.ts", "!**/build/**", "!/FrontEnd/**"],
forceCoverageMatch: ["**/*.test.ts"],
coverageDirectory: "Tests/coverage",
coverageReporters: ["lcov"],
rootDir: "..",
testMatch: ["**/*.test.ts"],
testEnvironment: "node",
globals: {
"ts-jest": {
tsConfig: "./tsconfig.json",
},
},
// testResultsProcessor: "jest-teamcity-reporter",
})
5 changes: 5 additions & 0 deletions e2e/__cases__/deep/src/Tests/tsconfig.json
@@ -0,0 +1,5 @@
{
"extends": "../tsconfig.base.node.json",
"compilerOptions": {
}
}
10 changes: 10 additions & 0 deletions e2e/__cases__/deep/src/tsconfig.base.json
@@ -0,0 +1,10 @@
{
"compilerOptions": {
"skipLibCheck": true,
"moduleResolution": "node",
"forceConsistentCasingInFileNames": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"strict": true
}
}
10 changes: 10 additions & 0 deletions e2e/__cases__/deep/src/tsconfig.base.node.json
@@ -0,0 +1,10 @@
{
"extends": "./tsconfig.base.json",
"compilerOptions": {
"module": "commonjs",
"target": "es2017",
"lib": [
"es2017"
]
}
}
5 changes: 5 additions & 0 deletions e2e/__cases__/deep/tsconfig.json
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"esModuleInterop": true
}
}
271 changes: 271 additions & 0 deletions e2e/__tests__/__snapshots__/deep-path.test.ts.snap
@@ -0,0 +1,271 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Deep paths test should pass using template "default": lcov 1`] = `
"TN:
SF:<cwd>/src/Button/click.ts
FN:3,click
FNF:1
FNH:1
FNDA:1,click
DA:1,1
DA:3,1
DA:4,1
LF:3
LH:3
BRF:0
BRH:0
end_of_record
TN:
SF:<cwd>/src/Tests/Button/click.test.ts
FN:3,(anonymous_0)
FNF:1
FNH:1
FNDA:1,(anonymous_0)
DA:1,1
DA:3,1
DA:4,1
LF:3
LH:3
BRF:0
BRH:0
end_of_record
"
`;
exports[`Deep paths test should pass using template "default": output 1`] = `
√ npm -s run test
↳ exit code: 0
===[ STDOUT ]===================================================================
=============================== Coverage summary ===============================
Statements : 100% ( 6/6 )
Branches : 100% ( 0/0 )
Functions : 100% ( 2/2 )
Lines : 100% ( 6/6 )
================================================================================
===[ STDERR ]===================================================================
PASS Button/click.test.ts
√ button should click!
Test Suites: 1 passed, 1 total
Tests: 1 passed, 1 total
Snapshots: 0 total
Time: XXs
Ran all test suites.
================================================================================
`;
exports[`Deep paths test should pass using template "with-babel-6": lcov 1`] = `
"TN:
SF:<cwd>/src/Button/click.ts
FN:3,click
FNF:1
FNH:1
FNDA:1,click
DA:1,1
DA:3,1
DA:4,1
LF:3
LH:3
BRF:0
BRH:0
end_of_record
TN:
SF:<cwd>/src/Tests/Button/click.test.ts
FN:3,(anonymous_0)
FNF:1
FNH:1
FNDA:1,(anonymous_0)
DA:1,1
DA:3,1
DA:4,1
LF:3
LH:3
BRF:0
BRH:0
end_of_record
"
`;
exports[`Deep paths test should pass using template "with-babel-6": output 1`] = `
√ npm -s run test
↳ exit code: 0
===[ STDOUT ]===================================================================
=============================== Coverage summary ===============================
Statements : 100% ( 6/6 )
Branches : 100% ( 0/0 )
Functions : 100% ( 2/2 )
Lines : 100% ( 6/6 )
================================================================================
===[ STDERR ]===================================================================
PASS Button/click.test.ts
√ button should click!
Test Suites: 1 passed, 1 total
Tests: 1 passed, 1 total
Snapshots: 0 total
Time: XXs
Ran all test suites.
================================================================================
`;
exports[`Deep paths test should pass using template "with-babel-7": lcov 1`] = `
"TN:
SF:<cwd>/src/Button/click.ts
FN:3,click
FNF:1
FNH:1
FNDA:1,click
DA:1,1
DA:3,1
DA:4,1
LF:3
LH:3
BRF:0
BRH:0
end_of_record
TN:
SF:<cwd>/src/Tests/Button/click.test.ts
FN:3,(anonymous_0)
FNF:1
FNH:1
FNDA:1,(anonymous_0)
DA:1,1
DA:3,1
DA:4,1
LF:3
LH:3
BRF:0
BRH:0
end_of_record
"
`;
exports[`Deep paths test should pass using template "with-babel-7": output 1`] = `
√ npm -s run test
↳ exit code: 0
===[ STDOUT ]===================================================================
=============================== Coverage summary ===============================
Statements : 100% ( 6/6 )
Branches : 100% ( 0/0 )
Functions : 100% ( 2/2 )
Lines : 100% ( 6/6 )
================================================================================
===[ STDERR ]===================================================================
PASS Button/click.test.ts
√ button should click!
Test Suites: 1 passed, 1 total
Tests: 1 passed, 1 total
Snapshots: 0 total
Time: XXs
Ran all test suites.
================================================================================
`;
exports[`Deep paths test should pass using template "with-jest-22": lcov 1`] = `
"TN:
SF:<cwd>/src/Button/click.ts
FN:3,click
FNF:1
FNH:1
FNDA:1,click
DA:1,1
DA:3,1
DA:4,1
LF:3
LH:3
BRF:0
BRH:0
end_of_record
TN:
SF:<cwd>/src/Tests/Button/click.test.ts
FN:3,(anonymous_0)
FNF:1
FNH:1
FNDA:1,(anonymous_0)
DA:1,1
DA:3,1
DA:4,1
LF:3
LH:3
BRF:0
BRH:0
end_of_record
"
`;
exports[`Deep paths test should pass using template "with-jest-22": output 1`] = `
√ npm -s run test
↳ exit code: 0
===[ STDOUT ]===================================================================
=============================== Coverage summary ===============================
Statements : 100% ( 6/6 )
Branches : 100% ( 0/0 )
Functions : 100% ( 2/2 )
Lines : 100% ( 6/6 )
================================================================================
===[ STDERR ]===================================================================
PASS Button/click.test.ts
√ button should click!
Test Suites: 1 passed, 1 total
Tests: 1 passed, 1 total
Snapshots: 0 total
Time: XXs
Ran all test suites.
================================================================================
`;
exports[`Deep paths test should pass using template "with-typescript-2-7": lcov 1`] = `
"TN:
SF:<cwd>/src/Button/click.ts
FN:3,click
FNF:1
FNH:1
FNDA:1,click
DA:1,1
DA:3,1
DA:4,1
LF:3
LH:3
BRF:0
BRH:0
end_of_record
TN:
SF:<cwd>/src/Tests/Button/click.test.ts
FN:3,(anonymous_0)
FNF:1
FNH:1
FNDA:1,(anonymous_0)
DA:1,1
DA:3,1
DA:4,1
LF:3
LH:3
BRF:0
BRH:0
end_of_record
"
`;
exports[`Deep paths test should pass using template "with-typescript-2-7": output 1`] = `
√ npm -s run test
↳ exit code: 0
===[ STDOUT ]===================================================================
=============================== Coverage summary ===============================
Statements : 100% ( 6/6 )
Branches : 100% ( 0/0 )
Functions : 100% ( 2/2 )
Lines : 100% ( 6/6 )
================================================================================
===[ STDERR ]===================================================================
PASS Button/click.test.ts
√ button should click!
Test Suites: 1 passed, 1 total
Tests: 1 passed, 1 total
Snapshots: 0 total
Time: XXs
Ran all test suites.
================================================================================
`;
20 changes: 20 additions & 0 deletions e2e/__tests__/deep-path.test.ts
@@ -0,0 +1,20 @@
import { readFileSync } from 'fs'
import { join } from 'path'

import { allValidPackageSets } from '../__helpers__/templates'
import { configureTestCase } from '../__helpers__/test-case'

describe('Deep paths test', () => {
const testCase = configureTestCase('deep')

testCase.runWithTemplates(allValidPackageSets, 0, (runTest, { testLabel }) => {
it(testLabel, () => {
const result = runTest()
expect(result.status).toBe(0)
expect(result).toMatchSnapshot('output')
let content: string = readFileSync(join(result.cwd, 'src', 'Tests', 'coverage', 'lcov.info'), 'utf8')
content = result.normalize(content)
expect(content).toMatchSnapshot('lcov')
})
})
})

0 comments on commit 0141098

Please sign in to comment.