Skip to content

Commit

Permalink
Merge branch 'beta' into kulshekhar-patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
huafu committed Sep 10, 2018
2 parents d673bc9 + 66633d5 commit 91e29ff
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 30 deletions.
20 changes: 17 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,36 @@ cache:

node_js:
- "10"
- "8"
- "6"

sudo: false

before_install:
# https://github.com/scikit-learn/scikit-learn/issues/10927
- |
set -e
# fail loudly when force-pushed, that is why there is the `|| 'dummy.js'` part
MODIFIED_FILES=$(git diff --name-only $TRAVIS_COMMIT_RANGE || echo 'dummy.js')
# waiting for native solution https://github.com/travis-ci/travis-ci/issues/6301
if ! echo ${MODIFIED_FILES} | grep -qvE '(\.md$)|(^docs)/'; then
if ! echo ${MODIFIED_FILES} | grep -qvE '^docs/|^\.gitignore|^\.gitattributes|\.md$|^appveyor\.yml$|^icon\.png$|^commitlint\.config\.js$'; then
echo "Only docs were updated, stopping build process."
exit
fi
# ensure we have npm >= 5.8 so that we can use `npm ci` instead of `npm install` (much faster)
- dpkg --compare-versions `npm -v` ge 5.8 || npm i -g npm@latest
# we report coverages only within node 10, ensure we have the coveralls bin installed
- 'if [[ "$(node --version)" == v10.* ]]; then npm install --global coveralls; fi'

script:
- npm run clean -- --when-ci-commit-message
- npm run test -- --coverage
# only grab coverage data on node 10
- |
if [[ "$(node --version)" == v10.* ]]; then
npm run test -- --coverage;
else
npm run test;
fi
after_success:
# report coverages to coveralls
- 'if [[ "$(node --version)" == v10.* && -s coverage/lcov.info ]]; then cat coverage/lcov.info | coveralls; fi'
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# ts-jest [![npm version](https://badge.fury.io/js/ts-jest.svg)](https://badge.fury.io/js/ts-jest) [![NPM downloads](https://img.shields.io/npm/dm/ts-jest.svg?style=flat)](https://npmjs.org/package/ts-jest) [![Known Vulnerabilities](https://snyk.io/test/github/kulshekhar/ts-jest/badge.svg)](https://snyk.io/test/github/kulshekhar/ts-jest) [![Build Status for linux](https://travis-ci.org/kulshekhar/ts-jest.svg?branch=master)](https://travis-ci.org/kulshekhar/ts-jest) [![Build Status for Windows](https://ci.appveyor.com/api/projects/status/g8tt9qd7usv0tolb/branch/master?svg=true)](https://ci.appveyor.com/project/kulshekhar/ts-jest/branch/master)
# ts-jest [![npm version](https://badge.fury.io/js/ts-jest.svg)](https://badge.fury.io/js/ts-jest) [![NPM downloads](https://img.shields.io/npm/dm/ts-jest.svg?style=flat)](https://npmjs.org/package/ts-jest) [![Known Vulnerabilities](https://snyk.io/test/github/kulshekhar/ts-jest/badge.svg)](https://snyk.io/test/github/kulshekhar/ts-jest) [![Coverage Status](https://coveralls.io/repos/github/kulshekhar/ts-jest/badge.svg?branch=master)](https://coveralls.io/github/kulshekhar/ts-jest?branch=master) [![Build Status for linux](https://travis-ci.org/kulshekhar/ts-jest.svg?branch=master)](https://travis-ci.org/kulshekhar/ts-jest) [![Build Status for Windows](https://ci.appveyor.com/api/projects/status/g8tt9qd7usv0tolb/branch/master?svg=true)](https://ci.appveyor.com/project/kulshekhar/ts-jest/branch/master)

<img src="./icon.png" align="right"
title="TSJest Logo by Huafu Gandon" width="128" height="128">
Expand Down
31 changes: 22 additions & 9 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,37 @@
# http://www.appveyor.com/docs/appveyor-yml
platform:
- x64
init:
- ps: IF ($env:APPVEYOR_REPO_COMMIT_MESSAGE -Match "\[clean ci-cache\]" ) {$env:APPVEYOR_CACHE_SKIP_RESTORE = "true"}
- ps: IF ($env:APPVEYOR_REPO_COMMIT_MESSAGE_EXTENDED -Match "\[clean ci-cache\]") {$env:APPVEYOR_CACHE_SKIP_RESTORE = "true"}

# Set build version format here instead of in the admin panel.
version: "{build}"

# branches to build
branches:
# blacklist
except:
- gh-pages

# Test against these versions of Node.js.
environment:
matrix:
- nodejs_version: "10"
- nodejs_version: "8"
- nodejs_version: "6"

matrix:
fast_finish: true # set this flag to immediately finish build once one of the jobs fails.

# Install scripts. (runs after repo cloning)
install:
- git rev-parse HEAD
# Get the latest stable version of Node 0.STABLE.latest
- ps: Install-Product node $env:nodejs_version
- ps: Install-Product node $env:nodejs_version x64
# Typical npm stuff.
- set CI=true
# Our E2E work dir
- set TS_JEST_E2E_WORKDIR=%APPDATA%\ts-jest-e2e
- npm -g install npm@latest
- npm ci || npm install
- npm install -g npm@^5
- npm ci --ignore-scripts
- npm run clean -- --when-ci-commit-message

cache:
Expand All @@ -28,13 +40,14 @@ cache:

# Post-install test scripts.
test_script:
- cmd: npm run test -- --coverage
- cmd: npm run test

# Don't actually build.
build: off

# Set build version format here instead of in the admin panel.
version: "{build}"
# Uses GitHub API to download the repo without git history
# @see: https://www.appveyor.com/docs/how-to/repository-shallow-clone/#downloading-repository-via-github-or-bitbucket-api
shallow_clone: true

skip_commits:
files:
Expand Down
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,7 @@
"yargs-parser": "^10.1.0"
},
"peerDependencies": {
"babel-jest": ">=22 <24",
"jest": ">=22 <24",
"typescript": ">=2.7.0 <4.0.0"
"jest": ">=22 <24"
},
"devDependencies": {
"@commitlint/cli": "^7.1.2",
Expand Down
12 changes: 4 additions & 8 deletions src/transformers/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,9 @@ See https://dev.doctorevidence.com/how-to-write-a-typescript-transform-plugin-fc
## Boilerplate

```ts
import {
TransformationContext,
SourceFile,
Visitor,
Transformer,
} from 'typescript';
import { ConfigSet } from '../config-set'
import { SourceFile, TransformationContext, Transformer, Visitor } from 'typescript'

import { ConfigSet } from '../config/config-set'

// this is a unique identifier for your transformer
export const name = 'my-transformer'
Expand All @@ -26,7 +22,7 @@ export function factory(cs: ConfigSet) {
// new nodes if we want to leave the node as is, and
// continue searching through child nodes:
return ts.visitEachChild(node, visitor, ctx)
};
}
return visitor
}
// we return the factory expected in CustomTransformers
Expand Down
12 changes: 7 additions & 5 deletions src/transformers/hoisting.ts → src/transformers/hoist-jest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,17 @@ export function factory(cs: ConfigSet) {
enter()

// visit each child
const resultNode = ts.visitEachChild(node, visitor, ctx)
let resultNode = ts.visitEachChild(node, visitor, ctx)

// check if we have something to hoist in this level
if (hoisted[level] && hoisted[level].length) {
// re-order children so that hoisted ones appear first
// this is actually the main work of this transformer
const block = resultNode as Block
block.statements = ts.createNodeArray([...hoisted[level], ...block.statements])
// this is actually the main job of this transformer
const hoistedStmts = hoisted[level]
const otherStmts = (resultNode as Block).statements.filter(s => !hoistedStmts.includes(s))
const newNode = ts.getMutableClone(resultNode) as Block
newNode.statements = ts.createNodeArray([...hoistedStmts, ...otherStmts])
resultNode = newNode
}

// exit the level
Expand All @@ -114,7 +117,6 @@ export function factory(cs: ConfigSet) {
if (shouldHoistNode(resultNode)) {
// hoist into current level
hoist(resultNode as Statement)
return
}

// finsally returns the currently visited node
Expand Down
2 changes: 1 addition & 1 deletion src/transformers/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AstTransformerDesc } from '../types'

import * as hoisting from './hoisting'
import * as hoisting from './hoist-jest'

export const internals: AstTransformerDesc[] = [hoisting]

0 comments on commit 91e29ff

Please sign in to comment.