-
Notifications
You must be signed in to change notification settings - Fork 583
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor/reorg test driver to resurect browser testing. #1868
Changes from 4 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,48 @@ | ||
var express = require('express'); | ||
var http = require('http'); | ||
var serveIndex = require('serve-index'); | ||
// Copyright 2015 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 {globPatterns} from '../test/modular/NodeTraceurTestRunner.js'; | ||
|
||
let express = require('express'); | ||
let http = require('http'); | ||
let serveIndex = require('serve-index'); | ||
|
||
function servePathAtPort(path, port) { | ||
var app = express(); | ||
app.use(express.static(path)); // before directory to allow index.html to work | ||
let app = express(); | ||
// serveIndex must precede static to allow index.html to work | ||
app.use(serveIndex(path)); | ||
var server = http.createServer(app); | ||
app.use(express.static(path)); | ||
// Expand the test list based on the file system. | ||
app.get('/traceurService/testGlobs', function(req, res) { | ||
let patterns = JSON.parse(req.query.patterns); | ||
return globPatterns(patterns).then((files) => { | ||
let nodeless = []; | ||
files.forEach((file) => { | ||
if (file.indexOf('/node/') === -1) { | ||
nodeless.push(file); | ||
} | ||
}); | ||
return res.send(nodeless); | ||
}); | ||
}); | ||
let server = http.createServer(app); | ||
server.on('error', function(e) { | ||
console.log('Port ' + port + ' did not work out'); | ||
console.error('Port ' + port + ' did not work out'); | ||
}); | ||
server.listen.apply(server, [port]); | ||
console.log('serving ' + path + ' at ' + port); | ||
} | ||
|
||
servePathAtPort(__dirname + '/..', 8099); | ||
servePathAtPort(__dirname + '/..', 80); | ||
servePathAtPort(System.dirname(__moduleName) + '/..', 8099); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a Node script, so __dirname should be available. (i.e., since require is available, so is __dirname). Better to use the "standard" version than the Traceur-specific one, I think. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd like to shoot for 100% self-hosting, so I'd like this file to be es6 also. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should experiment with the 'asynchronous import' loader ideas to see if anything reasonable can be done for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure what you mean by "We should experiment with the 'asynchronous import' loader ideas"? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. whatwg/loader#36 To be honest, I think such experimenting would be mostly for furn. I think node will just continue on with the require wrapper thing. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't want to hold you up based on this. Lets move on. |
||
servePathAtPort(System.dirname(__moduleName) + '/..', 80); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Copyright 2015 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. | ||
|
||
/** @fileoverview Configure mocha for Traceur testing.in browsers */ | ||
|
||
import {TraceurTestRunner} from './TraceurTestRunner.js'; | ||
import {webLoader} from '../../src/runtime/webLoader.js'; | ||
|
||
export class BrowserTraceurTestRunner extends TraceurTestRunner { | ||
|
||
constructor(traceurTestOptions) { | ||
super({ | ||
reporter: 'html', | ||
ui: 'tdd', | ||
importMetadata: { | ||
traceurOptions: { | ||
sourceMaps: 'inline' | ||
} | ||
} | ||
}, traceurTestOptions); | ||
} | ||
|
||
expandPatterns() { | ||
let url = './traceurService/testGlobs?patterns='; | ||
url += encodeURIComponent(JSON.stringify(this.patterns_)); | ||
return new Promise((resolve, reject) => { | ||
webLoader.load(url, (files) => { | ||
resolve(JSON.parse(files).forEach((file) => this.addFile(file))); | ||
}, (ex) => { | ||
console.error(url + ' FAILED ', ex.stack || ex); | ||
}); | ||
}); | ||
} | ||
|
||
getOptions() { | ||
return this.defaultOptions(); | ||
} | ||
|
||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Copyright 2015 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. | ||
|
||
/** @fileoverview Mocha dependencies from Node */ | ||
|
||
export let Mocha; | ||
export let Runner; | ||
export let reporters; | ||
|
||
if (typeof window === 'undefined') { | ||
Mocha = require('mocha'); | ||
Runner = require('mocha/lib/runner'); | ||
reporters = require('mocha/lib/reporters'); | ||
} else { | ||
Mocha = window.Mocha; | ||
Runner = Mocha.Runner; | ||
reporters = Mocha.reporters; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
// Copyright 2015 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. | ||
|
||
/** @fileoverview Configure mocha for Traceur testing on node. */ | ||
|
||
import {TraceurTestRunner} from './TraceurTestRunner.js'; | ||
|
||
export function globPatterns(patterns) { | ||
// This require will cause a compile error if at module scope. | ||
// TOOD async load the class. | ||
let glob = require('glob'); | ||
return Promise.all( | ||
patterns.map((pattern) => { | ||
return new Promise((resolve, reject) => { | ||
glob(pattern, {}, (err, files) => { | ||
if (err) { | ||
reject(err); | ||
} else { | ||
resolve(files); | ||
} | ||
}); | ||
}); | ||
})).then((arrayOfFiles) => { | ||
let allFiles = []; | ||
arrayOfFiles.forEach((files) => { | ||
allFiles.push(...files); | ||
}); | ||
return allFiles; | ||
}); | ||
} | ||
|
||
export class NodeTraceurTestRunner extends TraceurTestRunner { | ||
constructor(traceurTestOptions) { | ||
super({ | ||
ui: 'tdd', | ||
ignoreLeaks: true, | ||
importMetadata: { | ||
traceurOptions: { | ||
sourceMaps: 'memory', | ||
require: true // Some unit tests use require() | ||
} | ||
} | ||
}, traceurTestOptions); | ||
} | ||
|
||
// Reads process arguments, merges defaults options, returns options object. | ||
getOptions() { | ||
let {Command} = require('commander'); | ||
let testOptions = this.defaultOptions(); | ||
let commandLine = | ||
new Command(process.argv[0] + ' ' + process.argv[1]); | ||
|
||
Object.keys(testOptions).forEach((prop) => { | ||
commandLine[prop] = testOptions[prop]; | ||
}); | ||
|
||
commandLine.option('-?, --help', 'Show this help text', () => { | ||
commandLine.help(); | ||
}).usage('[options] [files]') | ||
|
||
// Selected mocha options supported. | ||
commandLine.option('-g, --grep <pattern>', 'only run tests matching <pattern>'). | ||
option('-i, --invert', 'inverts --grep matches'). | ||
option('-b, --bail', 'bail after first test failure'); | ||
|
||
commandLine.command('only <file> [files...]'). | ||
description('only test these [files] ').action( | ||
(file, files) => { | ||
commandLine.patterns = [file]; | ||
if (files) | ||
commandLine.patterns = commandLine.patterns.concat(files); | ||
}); | ||
|
||
commandLine.parse(process.argv); | ||
|
||
return commandLine; | ||
} | ||
|
||
expandPatterns() { | ||
return globPatterns(this.patterns_).then((files) => { | ||
files.forEach((file) => this.addFile(file)); | ||
}); | ||
} | ||
|
||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this need a copyright header?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done