-
Notifications
You must be signed in to change notification settings - Fork 11
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
6 changed files
with
61 additions
and
30 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 |
---|---|---|
@@ -1,21 +1,42 @@ | ||
'use strict'; | ||
|
||
const path = require('path'); | ||
const ts = require('typescript'); | ||
|
||
let pattern = 'test/**/*.@(ts|tsx)'; | ||
const cwd = process.cwd(); | ||
const packageData = require(path.join(cwd, 'package.json')); | ||
const compilerOptions = loadCompilerOptions(cwd) || {}; | ||
const extensions = ['ts', 'tsx']; | ||
if (compilerOptions.allowJs) { | ||
extensions.push('js'); | ||
extensions.push('jsx'); | ||
} | ||
|
||
let testDir = 'test'; | ||
const packageData = require(path.join(cwd, 'package.json')); | ||
if ( | ||
packageData && | ||
typeof packageData.directories === 'object' && | ||
typeof packageData.directories.test === 'string' | ||
) { | ||
const testDir = packageData.directories.test; | ||
pattern = `${testDir + (testDir.lastIndexOf('/', 0) === 0 ? '' : '/')}**/*.@(ts|tsx)`; | ||
testDir = packageData.directories.test; | ||
} | ||
const pattern = path.join(testDir, `**/*.@(${extensions.join('|')})`); | ||
|
||
require('./index')({ | ||
cwd: cwd, | ||
pattern: pattern, | ||
}); | ||
require('./index')({cwd, pattern, extensions}); | ||
|
||
function loadCompilerOptions(cwd) { | ||
const tsconfigPath = ts.findConfigFile(cwd, ts.sys.fileExists); | ||
if (!tsconfigPath) { | ||
return null; | ||
} | ||
const result = ts.readConfigFile(tsconfigPath, ts.sys.readFile); | ||
if (result.error) { | ||
throw new Error(result.error.messageText); | ||
} | ||
if (result.config && result.config.compilerOptions) { | ||
const basepath = path.dirname(tsconfigPath); | ||
const {options} = ts.parseJsonConfigFileContent(result.config, ts.sys, basepath); | ||
return options; | ||
} | ||
return null; | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,10 +1,11 @@ | ||
import assert = require('assert'); | ||
// don't use `assert` not to instrument | ||
import ass = require('assert'); | ||
|
||
export default function expectPowerAssertMessage(body: () => void, expectedLines: string) { | ||
try { | ||
body(); | ||
assert.fail('AssertionError should be thrown'); | ||
ass.fail('AssertionError should be thrown'); | ||
} catch(e) { | ||
assert.equal(e.message.split('\n').slice(2, -1).join('\n'), expectedLines); | ||
ass.equal(e.message.split('\n').slice(2, -1).join('\n'), expectedLines); | ||
} | ||
}; |
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