-
Notifications
You must be signed in to change notification settings - Fork 581
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use mocha --compilers to test import runtime
- Loading branch information
Showing
11 changed files
with
137 additions
and
54 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,69 @@ | ||
// Copyright 2016 Traceur Authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
import {CommandOptions} from '../Options.js'; | ||
|
||
function forEachPrologLine(s, f) { | ||
let inProlog = true; | ||
for (let i = 0; inProlog && i < s.length; ) { | ||
let j = s.indexOf('\n', i); | ||
if (j == -1) | ||
break; | ||
if (s[i] === '/' && s[i + 1] === '/') { | ||
let line = s.slice(i, j); | ||
f(line); | ||
i = j + 1; | ||
} else { | ||
inProlog = false; | ||
} | ||
} | ||
} | ||
|
||
export default function parseProlog(source) { | ||
let returnValue = { | ||
onlyInBrowser: false, | ||
skip: false, | ||
get shouldHaveErrors() { | ||
return this.expectedErrors.length !== 0; | ||
}, | ||
expectedErrors: [], | ||
async: false | ||
}; | ||
forEachPrologLine(source, (line) => { | ||
let m; | ||
if (line.indexOf('// Only in browser.') === 0) { | ||
returnValue.onlyInBrowser = true; | ||
} else if (line.indexOf('// Skip') === 0) { | ||
if (line.indexOf('// Skip.') === 0) { | ||
returnValue.skip = true; | ||
} else { | ||
// eval remainder of line. | ||
let skip = false; | ||
try { | ||
skip = eval(line.slice('// Skip'.length)); | ||
} catch (ex) { | ||
skip = true; | ||
} | ||
returnValue.skip = !!skip; | ||
} | ||
} else if (line.indexOf('// Async.') === 0) { | ||
returnValue.async = true; | ||
} else if ((m = /\/\ Options:\s*(.+)/.exec(line))) { | ||
returnValue.traceurOptions = traceur.util.CommandOptions.fromString(m[1]); | ||
} else if ((m = /\/\/ Error:\s*(.+)/.exec(line))) { | ||
returnValue.expectedErrors.push(m[1]); | ||
} | ||
}); | ||
return returnValue; | ||
} |
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,53 @@ | ||
'use strict'; | ||
|
||
var fs = require('fs'); | ||
var traceurAPI = require('../src/node/api.js'); | ||
|
||
var org = require.extensions['.js']; | ||
require.extensions['.js'] = function(module, path) { | ||
if (!/\/node_modules\//.test(path)) { | ||
var content = fs.readFileSync(path, 'utf8'); | ||
if (shouldSkip(path, content)) { | ||
return; | ||
} | ||
|
||
// TODO(arv): Reuse parseProlog. | ||
var compiled = traceurAPI.compile(content, { | ||
modules: 'commonjs', | ||
importRuntime: true, | ||
}, path, path); | ||
|
||
|
||
if (needsWrapper(path)) { | ||
var header = 'var assert = require("chai").assert, test = require("mocha").test;' + 'test("' + path + '", function(){'; | ||
var footer = '});'; | ||
compiled = header + compiled + footer; | ||
} | ||
|
||
try { | ||
return module._compile(compiled, path); | ||
} catch (ex) { | ||
console.log(compiled, path); | ||
throw ex; | ||
} | ||
} | ||
return org(module, path); | ||
}; | ||
|
||
function needsWrapper(path) { | ||
return /\/test\/feature\//.test(path) && !/\/resources\//.test(path); | ||
} | ||
|
||
var blackList = [ | ||
'/Modules/ModuleName.js', | ||
]; | ||
|
||
function shouldSkip(path, content) { | ||
for (var i = 0; i < blackList.length; i++) { | ||
if (path.indexOf(blackList[i]) !== -1) { | ||
return true; | ||
} | ||
} | ||
return /\/\/ (Error:|Options:|Skip.|Async.)/.test(content) || | ||
/\.script\.js$/.test(path); | ||
} |
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,3 +1,5 @@ | ||
import {assert} from '../../asserts.js'; | ||
|
||
import x from './resources/default.js'; | ||
assert.equal(x, 42); | ||
|
||
|
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,3 +1,5 @@ | ||
import {assert} from '../../../asserts.js'; | ||
|
||
export default class C { | ||
m() { | ||
return 'm'; | ||
|
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,3 +1,5 @@ | ||
import {assert} from '../../../asserts.js'; | ||
|
||
export default function f() { | ||
return 123; | ||
} | ||
|
File renamed without changes.
File renamed without changes.
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,3 +1,5 @@ | ||
|
||
import {assert} from '../../../asserts.js'; | ||
import {f} from './f.js'; | ||
|
||
assert.equal('a', (f `a`)[0][0]); |
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,3 +1,4 @@ | ||
import {assert} from '../../../asserts.js'; | ||
import {f} from './f.js'; | ||
|
||
assert.equal('b', (f `b`)[0][0]); |
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