-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
156 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,7 @@ jobs: | |
npm install --ignore-scripts | ||
- name: Run tests | ||
shell: bash | ||
run: | | ||
npm run test:ci | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -108,3 +108,6 @@ dist | |
|
||
# TernJS port file | ||
.tern-port | ||
|
||
# Generated files | ||
test/ts/*js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { EventEmitter } from 'events' | ||
|
||
declare class ThreadStream extends EventEmitter { | ||
constructor(opts: {}) | ||
write (data: string): boolean | ||
end (): void | ||
} | ||
|
||
export = ThreadStream; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export declare function file(): string |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
'use strict' | ||
|
||
const { test } = require('tap') | ||
const { join } = require('path') | ||
const { file } = require('./helper') | ||
const ThreadStream = require('..') | ||
|
||
function basic (esVersion) { | ||
test(`transpiled-ts-to-${esVersion}`, function (t) { | ||
t.plan(2) | ||
|
||
const dest = file() | ||
const stream = new ThreadStream({ | ||
filename: join(__dirname, 'ts', `to-file.${esVersion}.cjs`), | ||
workerData: { dest }, | ||
sync: true | ||
}) | ||
|
||
// There are arbitrary checks, the important aspect of this test is to ensure | ||
// that we can properly load the transpiled file into our worker thread. | ||
t.same(stream.writableEnded, false) | ||
stream.end() | ||
t.same(stream.writableEnded, true) | ||
}) | ||
} | ||
|
||
basic('es5') | ||
basic('es6') | ||
basic('es2017') | ||
basic('esnext') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { test } from 'tap' | ||
import { readFile } from 'fs' | ||
import ThreadStream from '../index.js' | ||
import { join } from 'path' | ||
import { file } from './helper.js' | ||
|
||
|
||
test('typescript module', function (t) { | ||
if (process.platform === 'win32') { | ||
// TODO: Implement .ts files loading support for Windows | ||
t.plan(0) | ||
return | ||
} | ||
|
||
t.plan(5) | ||
|
||
const dest = file() | ||
const stream = new ThreadStream({ | ||
filename: join(__dirname, 'ts', 'to-file.ts'), | ||
workerData: { dest }, | ||
sync: true | ||
}) | ||
|
||
stream.on('finish', () => { | ||
readFile(dest, 'utf8', (err, data) => { | ||
t.error(err) | ||
t.equal(data, 'hello world\nsomething else\n') | ||
}) | ||
}) | ||
|
||
stream.on('close', () => { | ||
t.pass('close emitted') | ||
}) | ||
|
||
t.ok(stream.write('hello world\n')) | ||
t.ok(stream.write('something else\n')) | ||
|
||
stream.end() | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { type PathLike, type WriteStream, createWriteStream } from 'fs' | ||
import { once } from 'events' | ||
|
||
export default async function run ( | ||
opts: { dest: PathLike }, | ||
): Promise<WriteStream> { | ||
const stream = createWriteStream(opts.dest) | ||
await once(stream, 'open') | ||
return stream | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#!/bin/sh | ||
|
||
set -e | ||
|
||
cd ./test/ts; | ||
|
||
if (echo "${npm_config_user_agent}" | grep "yarn"); then | ||
export RUNNER="yarn"; | ||
else | ||
export RUNNER="npx"; | ||
fi | ||
|
||
test ./to-file.ts -ot ./to-file.es5.cjs || ("${RUNNER}" tsc --target es5 ./to-file.ts && mv ./to-file.js ./to-file.es5.cjs); | ||
test ./to-file.ts -ot ./to-file.es6.mjs || ("${RUNNER}" tsc --target es6 ./to-file.ts && mv ./to-file.js ./to-file.es6.mjs); | ||
test ./to-file.ts -ot ./to-file.es6.cjs || ("${RUNNER}" tsc --target es6 --module commonjs ./to-file.ts && mv ./to-file.js ./to-file.es6.cjs); | ||
test ./to-file.ts -ot ./to-file.es2017.mjs || ("${RUNNER}" tsc --target es2017 ./to-file.ts && mv ./to-file.js ./to-file.es2017.mjs); | ||
test ./to-file.ts -ot ./to-file.es2017.cjs || ("${RUNNER}" tsc --target es2017 --module commonjs ./to-file.ts && mv ./to-file.js ./to-file.es2017.cjs); | ||
test ./to-file.ts -ot ./to-file.esnext.mjs || ("${RUNNER}" tsc --target esnext --module esnext ./to-file.ts && mv ./to-file.js ./to-file.esnext.mjs); | ||
test ./to-file.ts -ot ./to-file.esnext.cjs || ("${RUNNER}" tsc --target esnext --module commonjs ./to-file.ts && mv ./to-file.js ./to-file.esnext.cjs); |