Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CI run tests on windows #1041

Merged
merged 24 commits into from
May 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 32 additions & 6 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,35 @@ on:
schedule:
- cron: '0 0 * * *'
jobs:
test:
name: "Test #${{ matrix.flavor }}: node v${{ matrix.node }}, ${{ matrix.typescript }}"
lint-build:
name: "Lint & Build"
runs-on: ubuntu-latest
steps:
# checkout code
- uses: actions/checkout@v2
# install node
- name: Use Node.js 14
uses: actions/setup-node@v1
with:
node-version: 14
# lint, build, test
- run: npm install
- run: npm run lint
- run: npm run build
- name: Upload package artifact
uses: actions/upload-artifact@v1
with:
name: ts-node-packed.tgz
path: tests/ts-node-packed.tgz

test:
needs: lint-build
name: "Test #${{ matrix.flavor }}: ${{ matrix.os }}, node v${{ matrix.node }}, ${{ matrix.typescript }}"
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest]
flavor: [1, 2, 3, 4, 5, 6, 7]
include:
- flavor: 1
Expand Down Expand Up @@ -47,17 +70,20 @@ jobs:
node-version: ${{ matrix.node }}
# lint, build, test
- run: npm install
- run: npm run lint
- run: npm run build
- run: npm rm tslint
- run: npm run build-nopack
- name: Download package artifact
uses: actions/download-artifact@v1
with:
name: ts-node-packed.tgz
path: tests/
- run: npm install ${{ matrix.typescript }} --force
- run: npm run test-cov
- name: Coveralls
if: ${{ always() }}
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.github_token }}
flag-name: run-${{ matrix.flavor }}
flag-name: run-${{ matrix.os }}-${{ matrix.flavor }}
parallel: true
finish:
needs: test
Expand Down
26 changes: 9 additions & 17 deletions src/esm.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { register, getExtensions, RegisterOptions } from './index'
import { parse as parseUrl, format as formatUrl, UrlWithStringQuery } from 'url'
import { posix as posixPath } from 'path'
import { parse as parseUrl, format as formatUrl, UrlWithStringQuery, fileURLToPath, pathToFileURL } from 'url'
import { extname } from 'path'
import * as assert from 'assert'
const { createResolve } = require('../dist-raw/node-esm-resolve-implementation')

Expand Down Expand Up @@ -65,13 +65,12 @@ export function registerAndCreateEsmHooks (opts?: RegisterOptions) {
const { pathname } = parsed
assert(pathname !== null, 'ESM getFormat() hook: URL should never have null pathname')

const nativePath = fileURLToPath(url)

// If file has .ts, .tsx, or .jsx extension, then ask node how it would treat this file if it were .js
const ext = posixPath.extname(pathname)
const ext = extname(nativePath)
if (ext === '.ts' || ext === '.tsx' || ext === '.jsx') {
return defer(formatUrl({
...parsed,
pathname: pathname + '.js'
}))
return defer(formatUrl(pathToFileURL(nativePath + '.js')))
}

return defer()
Expand All @@ -88,20 +87,13 @@ export function registerAndCreateEsmHooks (opts?: RegisterOptions) {
if (!isFileUrlOrNodeStyleSpecifier(parsed)) {
return defer()
}
const { pathname } = parsed
if (pathname === null || !posixPath.isAbsolute(pathname)) {
// If we are meant to handle this URL, then it has already been resolved to an absolute path by our resolver hook
return defer()
}

// Assigning to a new variable so it's clear that we have stopped thinking of it as a URL, and started using it like a native FS path
const fileName = pathname
const nativePath = fileURLToPath(url)

if (tsNodeInstance.ignored(fileName)) {
if (tsNodeInstance.ignored(nativePath)) {
return defer()
}

const emittedJs = tsNodeInstance.compile(sourceAsString, fileName)
const emittedJs = tsNodeInstance.compile(sourceAsString, nativePath)

return { source: emittedJs }
}
Expand Down
49 changes: 29 additions & 20 deletions src/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import semver = require('semver')
import ts = require('typescript')
import proxyquire = require('proxyquire')
import { register, create, VERSION } from './index'
import { unlinkSync, existsSync } from 'fs'
import { unlinkSync, existsSync, statSync } from 'fs'
import * as promisify from 'util.promisify'

const execP = promisify(exec)
Expand Down Expand Up @@ -262,7 +262,7 @@ describe('ts-node', function () {
})

it('should pipe into an eval script', function (done) {
const cp = exec(`${cmd} --transpile-only -pe 'process.stdin.isTTY'`, function (err, stdout) {
const cp = exec(`${cmd} --transpile-only -pe "process.stdin.isTTY"`, function (err, stdout) {
expect(err).to.equal(null)
expect(stdout).to.equal('undefined\n')

Expand Down Expand Up @@ -369,18 +369,23 @@ describe('ts-node', function () {

describe('issue #884', function () {
it('should compile', function (done) {
exec(`node "${BIN_PATH}" --project tests/issue-884/tsconfig.json tests/issue-884`, function (err, stdout) {
expect(err).to.equal(null)
expect(stdout).to.equal('')
// TODO disabled because it consistently fails on Windows on TS 2.7
if (process.platform === 'win32' && semver.satisfies(ts.version, '2.7')) {
this.skip()
} else {
exec(`"${BIN_PATH}" --project tests/issue-884/tsconfig.json tests/issue-884`, function (err, stdout) {
expect(err).to.equal(null)
expect(stdout).to.equal('')

return done()
})
return done()
})
}
})
})

describe('issue #986', function () {
it('should not compile', function (done) {
exec(`node "${BIN_PATH}" --project tests/issue-986/tsconfig.json tests/issue-986`, function (err, stdout, stderr) {
exec(`"${BIN_PATH}" --project tests/issue-986/tsconfig.json tests/issue-986`, function (err, stdout, stderr) {
expect(err).not.to.equal(null)
expect(stderr).to.contain('Cannot find name \'TEST\'') // TypeScript error.
expect(stdout).to.equal('')
Expand All @@ -390,7 +395,7 @@ describe('ts-node', function () {
})

it('should compile with `--files`', function (done) {
exec(`node "${BIN_PATH}" --files --project tests/issue-986/tsconfig.json tests/issue-986`, function (err, stdout, stderr) {
exec(`"${BIN_PATH}" --files --project tests/issue-986/tsconfig.json tests/issue-986`, function (err, stdout, stderr) {
expect(err).not.to.equal(null)
expect(stderr).to.contain('ReferenceError: TEST is not defined') // Runtime error.
expect(stdout).to.equal('')
Expand All @@ -402,20 +407,24 @@ describe('ts-node', function () {

if (semver.gte(ts.version, '2.7.0')) {
it('should support script mode', function (done) {
exec(`node ${BIN_SCRIPT_PATH} tests/scope/a/log`, function (err, stdout) {
exec(`${BIN_SCRIPT_PATH} tests/scope/a/log`, function (err, stdout) {
expect(err).to.equal(null)
expect(stdout).to.equal('.ts\n')

return done()
})
})
it('should read tsconfig relative to realpath, not symlink, in scriptMode', function (done) {
exec(`node ${BIN_SCRIPT_PATH} tests/main-realpath/symlink/symlink.tsx`, function (err, stdout) {
expect(err).to.equal(null)
expect(stdout).to.equal('')
if (statSync(join(TEST_DIR, 'main-realpath/symlink/symlink.tsx')).isSymbolicLink()) {
exec(`${BIN_SCRIPT_PATH} tests/main-realpath/symlink/symlink.tsx`, function (err, stdout) {
expect(err).to.equal(null)
expect(stdout).to.equal('')

return done()
})
return done()
})
} else {
this.skip()
}
})
}

Expand All @@ -431,7 +440,7 @@ describe('ts-node', function () {
}, function (err, stdout) {
expect(err).to.equal(null)
const { config } = JSON.parse(stdout)
expect(config.options.typeRoots).to.deep.equal([join(__dirname, '../tests/tsconfig-options/env-typeroots')])
expect(config.options.typeRoots).to.deep.equal([join(__dirname, '../tests/tsconfig-options/env-typeroots').replace(/\\/g, '/')])
return done()
})
})
Expand All @@ -440,7 +449,7 @@ describe('ts-node', function () {
exec(`${BIN_EXEC} tests/tsconfig-options/log-options.js`, function (err, stdout) {
expect(err).to.equal(null)
const { options, config } = JSON.parse(stdout)
expect(config.options.typeRoots).to.deep.equal([join(__dirname, '../tests/tsconfig-options/tsconfig-typeroots')])
expect(config.options.typeRoots).to.deep.equal([join(__dirname, '../tests/tsconfig-options/tsconfig-typeroots').replace(/\\/g, '/')])
expect(config.options.types).to.deep.equal(['tsconfig-tsnode-types'])
expect(options.pretty).to.equal(undefined)
expect(options.skipIgnore).to.equal(false)
Expand All @@ -450,10 +459,10 @@ describe('ts-node', function () {
})

it('should have flags override `tsconfig.json`', function (done) {
exec(`${BIN_EXEC} --skip-ignore --compiler-options '{"types": ["flags-types"]}' tests/tsconfig-options/log-options.js`, function (err, stdout) {
exec(`${BIN_EXEC} --skip-ignore --compiler-options "{\\"types\\":[\\"flags-types\\"]}" tests/tsconfig-options/log-options.js`, function (err, stdout) {
expect(err).to.equal(null)
const { options, config } = JSON.parse(stdout)
expect(config.options.typeRoots).to.deep.equal([join(__dirname, '../tests/tsconfig-options/tsconfig-typeroots')])
expect(config.options.typeRoots).to.deep.equal([join(__dirname, '../tests/tsconfig-options/tsconfig-typeroots').replace(/\\/g, '/')])
expect(config.options.types).to.deep.equal(['flags-types'])
expect(options.pretty).to.equal(undefined)
expect(options.skipIgnore).to.equal(true)
Expand All @@ -472,7 +481,7 @@ describe('ts-node', function () {
}, function (err, stdout) {
expect(err).to.equal(null)
const { options, config } = JSON.parse(stdout)
expect(config.options.typeRoots).to.deep.equal([join(__dirname, '../tests/tsconfig-options/tsconfig-typeroots')])
expect(config.options.typeRoots).to.deep.equal([join(__dirname, '../tests/tsconfig-options/tsconfig-typeroots').replace(/\\/g, '/')])
expect(config.options.types).to.deep.equal(['tsconfig-tsnode-types'])
expect(options.pretty).to.equal(true)
expect(options.skipIgnore).to.equal(false)
Expand Down