-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Include unit tests for Closure-based js code with selenium-webdriver …
…package.
- Loading branch information
Showing
5 changed files
with
203 additions
and
58 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
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,97 @@ | ||
// Copyright 2014 Software Freedom Conservancy. All Rights Reserved. | ||
// | ||
// 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. | ||
|
||
var assert = require('assert'), | ||
fs = require('fs'), | ||
path = require('path'); | ||
|
||
var base = require('../_base'); | ||
|
||
describe('Context', function() { | ||
it('does not pollute the global scope', function() { | ||
assert.equal('undefined', typeof goog); | ||
|
||
var context = new base.Context(); | ||
assert.equal('undefined', typeof goog); | ||
assert.equal('object', typeof context.closure.goog); | ||
|
||
context.closure.goog.require('goog.array'); | ||
assert.equal('undefined', typeof goog); | ||
assert.equal('object', typeof context.closure.goog.array); | ||
}); | ||
}); | ||
|
||
|
||
function runClosureTest(file) { | ||
var name = path.basename(file); | ||
name = name.substring(0, name.length - '.js'.length); | ||
|
||
describe(name, function() { | ||
var context = new base.Context(true); | ||
context.closure.document.title = name; | ||
// Null out console so everything loads silently. | ||
context.closure.console = null; | ||
context.closure.CLOSURE_IMPORT_SCRIPT(file); | ||
|
||
var tc = context.closure.G_testRunner.testCase; | ||
if (!tc) { | ||
tc = new context.closure.goog.testing.TestCase(name); | ||
tc.autoDiscoverTests(); | ||
} | ||
// Reset console for running tests. | ||
context.closure.console = console; | ||
|
||
var allTests = tc.getTests(); | ||
allTests.forEach(function(test) { | ||
it(test.name, function(done) { | ||
tc.setTests([test]); | ||
tc.setCompletedCallback(function() { | ||
if (tc.isSuccess()) { | ||
return done(); | ||
} | ||
var results = tc.getTestResults(); | ||
done(Error('\n' + Object.keys(results).map(function(name) { | ||
var msg = [name + ': ' + (results[name].length ? 'FAILED' : 'PASSED')]; | ||
if (results[name].length) { | ||
msg = msg.concat(results[name]); | ||
} | ||
return msg.join('\n'); | ||
}).join('\n'))); | ||
}); | ||
tc.runTests(); | ||
}); | ||
}); | ||
}); | ||
} | ||
|
||
|
||
function findTests(dir) { | ||
fs.readdirSync(dir).forEach(function(name) { | ||
var file = path.join(dir, name); | ||
|
||
var stat = fs.statSync(file); | ||
if (stat.isDirectory() && name !== 'atoms' && name !== 'e2e') { | ||
findTests(file); | ||
return; | ||
} | ||
|
||
var l = file.length - '_test.js'.length; | ||
if (l >= 0 && file.indexOf('_test.js', l) == l) { | ||
runClosureTest(file); | ||
} | ||
}); | ||
} | ||
|
||
findTests(path.join( | ||
__dirname, base.isDevMode() ? '../../..' : '../lib', 'webdriver/test')); |
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