-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds support for requiring external modules on startup (#550)
* Adds support for requiring external modules on startup * Add a test to verify the `--require` flag works. Only run it in full mode.
- Loading branch information
1 parent
eb15d1a
commit aecec56
Showing
3 changed files
with
55 additions
and
2 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
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,37 @@ | ||
import { standardizePath as s } from './util'; | ||
import * as fsExtra from 'fs-extra'; | ||
import { execSync } from 'child_process'; | ||
import { expect } from 'chai'; | ||
|
||
const tempDir = s`${process.cwd()}/.tmp`; | ||
const cliPath = s`${__dirname}/cli.ts`; | ||
|
||
describe('cli', () => { | ||
let idx = 0; | ||
let cwd: string; | ||
beforeEach(() => { | ||
cwd = s`${tempDir}/cli-test-${idx}`; | ||
fsExtra.ensureDirSync(cwd); | ||
}); | ||
afterEach(() => { | ||
fsExtra.emptyDirSync(cwd); | ||
}); | ||
|
||
if (process.argv.includes('--all')) { | ||
it('loads ts-node from the --require flag', () => { | ||
fsExtra.outputFileSync(s`${cwd}/manifest`, ''); | ||
const modulePath = s`${cwd}/module.js`; | ||
//simple plugin that writes a file. If the file exists, we know the require syntax works | ||
fsExtra.outputFileSync(modulePath, ` | ||
var fs = require('fs'); | ||
fs.writeFileSync('./testResult.txt', ''); | ||
`); | ||
execSync(`npx ts-node-transpile-only "${cliPath}" --require "${modulePath}"`, { | ||
cwd: cwd | ||
}); | ||
expect( | ||
fsExtra.pathExistsSync(s`${cwd}/testResult.txt`) | ||
).to.be.true; | ||
}); | ||
} | ||
}); |
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