Skip to content

Commit 5317114

Browse files
committed
Merge pull request #15 from power-assert-js/fix-outdir
fix(index): support outDir option
2 parents 584fc2c + e489059 commit 5317114

File tree

5 files changed

+57
-5
lines changed

5 files changed

+57
-5
lines changed

index.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
'use strict';
22

33
var fs = require('fs');
4+
var path = require('path');
45

56
var espowerSource = require('espower-source');
67
var minimatch = require('minimatch');
78
var ts = require('typescript');
89
var TypeScriptSimple = require('typescript-simple').TypeScriptSimple;
910

1011
function espowerTypeScript(options) {
12+
var cwd = options.cwd || process.cwd();
1113
var separator = (options.pattern.lastIndexOf('/', 0) === 0) ? '' : '/';
12-
var pattern = options.cwd + separator + options.pattern;
13-
var compilerOptions = convertCompilerOptions(options.compilerOptions, options.basepath);
14+
var pattern = cwd + separator + options.pattern;
15+
var compilerOptions = convertCompilerOptions(options.compilerOptions, options.basepath || cwd);
1416
var tss = new TypeScriptSimple(compilerOptions, false);
1517

1618
function loadTypeScript(localModule, filepath) {
17-
var result = tss.compile(fs.readFileSync(filepath, 'utf-8'));
19+
var result = tss.compile(fs.readFileSync(filepath, 'utf-8'), path.relative(cwd, filepath));
1820
if (minimatch(filepath, pattern)) {
1921
result = espowerSource(result, filepath, options);
2022
}
@@ -30,7 +32,6 @@ function convertCompilerOptions(compilerOptions, basepath) {
3032
return null;
3133
}
3234

33-
var basepath = basepath || process.cwd();
3435
var converted = ts.convertCompilerOptionsFromJson(compilerOptions, basepath);
3536
if (converted.errors && converted.errors.length > 0) {
3637
var msg = converted.errors.map(function(e) {return e.messageText}).join(', ');

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"description": "power-assert instrumentor for TypeScript",
55
"main": "index.js",
66
"scripts": {
7-
"test": "mocha --require './guess' test/*_test.ts"
7+
"test:outdir": "cd test/test-outdir && mocha --require ../../guess test/*_test.ts",
8+
"test": "mocha --require './guess' test/*_test.ts && npm run test:outdir"
89
},
910
"repository": {
1011
"type": "git",

test/test-outdir/package.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"name": "test-outdir",
3+
"version": "1.0.0",
4+
"description": "This is a dummy file. See ../../package.json",
5+
"devDependencies": {
6+
},
7+
"dependencies": {
8+
}
9+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
'use strict';
2+
3+
import assert = require('power-assert')
4+
import expect = require('expect.js')
5+
import MyComponent from '../lib/mycomponent.tsx';
6+
7+
describe('test for outDir option', function() {
8+
beforeEach(function() {
9+
this.expectPowerAssertMessage = (body: () => void, expectedLines: string) => {
10+
try {
11+
body();
12+
expect().fail('AssertionError should be thrown');
13+
} catch(e) {
14+
expect(e.message.split('\n').slice(2, -1).join('\n')).to.eql(expectedLines);
15+
}
16+
}
17+
});
18+
19+
it('equal with Literal and Identifier: assert.equal(1, minusOne)', function() {
20+
let minusOne: number = -1;
21+
let expected: string =
22+
` assert.equal(1, minusOne)
23+
|
24+
-1 `;
25+
this.expectPowerAssertMessage(() => {
26+
assert.equal(1, minusOne);
27+
}, expected);
28+
});
29+
});

test/test-outdir/tsconfig.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"compilerOptions": {
3+
"outDir": "build",
4+
"module": "commonjs",
5+
"target": "ES5",
6+
"noImplicitAny": true,
7+
"jsx": "react"
8+
},
9+
"exclude": [
10+
"node_modules"
11+
]
12+
}

0 commit comments

Comments
 (0)