Skip to content

Commit

Permalink
feat(tests): add test setup
Browse files Browse the repository at this point in the history
  • Loading branch information
cschroeter authored Oct 15, 2019
2 parents 7b60040 + 5c5f8dd commit a5b41b4
Show file tree
Hide file tree
Showing 9 changed files with 3,035 additions and 718 deletions.
7 changes: 5 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: 2
jobs:
build:
docker:
- image: circleci/node:8
- image: circleci/node:10.16.3
steps:
- checkout
- run:
Expand All @@ -11,6 +11,9 @@ jobs:
- run:
name: build
command: yarn build
- run:
name: test
command: yarn test
- run:
name: release
command: yarn release || true
command: yarn release
3 changes: 3 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
presets: [['@babel/preset-env', { targets: { node: 'current' } }], '@babel/preset-typescript'],
}
19 changes: 14 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,35 +22,44 @@
"scripts": {
"start": "tsc -w",
"build": "tsc",
"test": "CI=true jest",
"release": "semantic-release"
},
"dependencies": {
"chalk": "^2.4.2",
"execa": "^2.1.0",
"execa": "^3.1.0",
"simple-git": "^1.126.0",
"yargs": "^14.2.0"
},
"peerDependencies": {
"typescript": "3.x"
},
"devDependencies": {
"@babel/core": "7.6.4",
"@babel/preset-env": "7.6.3",
"@babel/preset-typescript": "7.6.0",
"@commitlint/cli": "8.2.0",
"@commitlint/config-conventional": "8.2.0",
"@semantic-release/changelog": "3.0.4",
"@semantic-release/commit-analyzer": "6.3.0",
"@semantic-release/git": "7.0.16",
"@semantic-release/npm": "5.2.0",
"@semantic-release/release-notes-generator": "7.3.0",
"@types/fs-extra": "8.0.0",
"@types/jest": "24.0.19",
"@types/yargs": "13.0.3",
"@typescript-eslint/eslint-plugin": "2.3.3",
"@typescript-eslint/parser": "2.3.3",
"@typescript-eslint/eslint-plugin": "2.4.0",
"@typescript-eslint/parser": "2.4.0",
"eslint": "6.5.1",
"eslint-config-prettier": "6.4.0",
"eslint-plugin-prettier": "3.1.1",
"husky": "3.0.8",
"fs-extra": "8.1.0",
"husky": "3.0.9",
"jest": "24.9.0",
"prettier": "1.18.2",
"pretty-quick": "1.11.1",
"pretty-quick": "2.0.0",
"semantic-release": "^15.13.24",
"tmp-promise": "2.0.2",
"typescript": "3.6.3"
},
"husky": {
Expand Down
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const getTypeScriptCompileOutput = async (options: TypeScriptOptions): Promise<s

let tscOutput: string[] = []
try {
await execa('tsc', args)
await execa('tsc', args, { all: true })
} catch (error) {
const { all } = error
tscOutput = (all as string).split('\n')
Expand Down
1 change: 1 addition & 0 deletions tests/repository/src/noImplicitAny.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
const foo = (arg): void => {}
6 changes: 6 additions & 0 deletions tests/repository/src/strictNullChecks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
interface User {
age?: number
}
const myUser: User = {}

console.log(myUser.age.toString())
6 changes: 6 additions & 0 deletions tests/repository/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"compilerOptions": {
"target": "es5",
"module": "commonjs"
}
}
51 changes: 51 additions & 0 deletions tests/ts-strictify.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import simpleGit from 'simple-git/promise'
import tmp from 'tmp-promise'
import execa from 'execa'
import { join } from 'path'
import { copy, outputFile } from 'fs-extra'

const runTsStrictifyInPath = async (path: string): Promise<string> => {
const cwd = process.cwd()
const tsStrictify = join(cwd, 'dist/bin.js')

process.chdir(path)
return execa('node', [tsStrictify])
.then((response) => response.stdout)
.catch((error) => error.stdout)
.finally(() => process.chdir(cwd))
}

test('files are detected correctly', async () => {
jest.setTimeout(20000)
const { path } = await tmp.dir()
const git = simpleGit(path)

await git
.init()
.then(() => git.addConfig('user.name', 'Some One'))
.then(() => git.addConfig('user.email', 'some@one.com'))
.then(() => copy(join(__dirname, 'repository'), path))
.then(() => git.add('./*'))
.then(() => git.commit('First commit'))
.then(() => runTsStrictifyInPath(path))
.then((stdout) => expect(stdout).toMatch(/Found 0 changed file/))

await git
.checkoutLocalBranch('feature')
.then(() => outputFile(join(path, 'foo.ts'), 'const foo = (arg): void => {}'))
.then(() => runTsStrictifyInPath(path))
.then((stdout) => {
expect(stdout).toMatch(/Found 1 changed file/)
expect(stdout).toMatch(/error TS7006: Parameter 'arg' implicitly has an 'any' type/)
})

await git
.add('./*')
.then(() => runTsStrictifyInPath(path))
.then((stdout) => expect(stdout).toMatch(/Found 1 changed file/))

await git
.commit('Second commit')
.then(() => runTsStrictifyInPath(path))
.then((stdout) => expect(stdout).toMatch(/Found 1 changed file/))
})
Loading

0 comments on commit a5b41b4

Please sign in to comment.