Skip to content

Commit

Permalink
Allow testing of platform specific modules
Browse files Browse the repository at this point in the history
- bundle in platform specific modules for the cordova.test.js file
- get rid of caching in the packager, was causing issues for how we
  generate webworks as well as browser based testing
- fixed the browser test runner to run platform specific tests (small
  regex fix)
- removed symlinks to android packages now that they are bundled in
- changed the included test platform in the btest from an injected
  script to a generated route that builds each time it is requested.
  • Loading branch information
gtanner committed Oct 9, 2012
1 parent 2033fdc commit e4561c4
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 26 deletions.
33 changes: 17 additions & 16 deletions build/packager.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,20 @@ packager.bundle = function(platform, debug, commitId ) {
copyProps(modules, collectFiles(path.join('lib', 'webworks/common')))
copyProps(modules, collectFiles(path.join('lib', 'webworks/' + lang)))
}
else if (platform === 'test') {
copyProps(modules, collectFiles(path.join('lib', platform)));

//Test platform needs to bring in platform specific plugin's for testing
copyProps(modules, collectFiles(path.join('lib', 'webworks', 'air', 'plugin', 'air'), 'plugin/air'));
copyProps(modules, collectFiles(path.join('lib', 'webworks', 'java', 'plugin', 'java'), 'plugin/java'));
copyProps(modules, collectFiles(path.join('lib', 'webworks', 'qnx', 'plugin', 'qnx'), 'plugin/qnx'));
copyProps(modules, collectFiles(path.join('lib', 'tizen', 'plugin', 'tizen'), 'plubin/tizen'));
copyProps(modules, collectFiles(path.join('lib', 'wp7', 'plugin', 'wp7'), 'plugin/wp7'));
copyProps(modules, collectFiles(path.join('lib', 'windows8', 'plugin', 'windows8'), 'plugin/windows8'));
copyProps(modules, collectFiles(path.join('lib', 'ios', 'plugin', 'ios'), 'plugin/ios/'));
copyProps(modules, collectFiles(path.join('lib', 'bada', 'plugin', 'bada'), 'plugin/bada/'));
copyProps(modules, collectFiles(path.join('lib', 'android', 'plugin', 'android'), 'plugin/android/'));
}
else {
copyProps(modules, collectFiles(path.join('lib', platform)))
}
Expand Down Expand Up @@ -121,7 +135,6 @@ packager.bundle = function(platform, debug, commitId ) {
}

//------------------------------------------------------------------------------
var CollectedFiles = {}

function collectFile(dir, id, entry) {
if (!id) id = ''
Expand All @@ -130,7 +143,7 @@ function collectFile(dir, id, entry) {

var stat = fs.statSync(fileName)

var result = CollectedFiles[dir] || {};
var result = {};

moduleId = getModuleId(moduleId)
result[moduleId] = fileName
Expand All @@ -140,10 +153,6 @@ function collectFile(dir, id, entry) {

function collectFiles(dir, id) {
if (!id) id = ''

if (CollectedFiles[dir]) {
return copyProps({}, CollectedFiles[dir])
}

var result = {}

Expand All @@ -157,7 +166,7 @@ function collectFiles(dir, id) {
})

entries.forEach(function(entry) {
var moduleId = path.join(id, entry)
var moduleId = path.join(id, entry)
var fileName = path.join(dir, entry)

var stat = fs.statSync(fileName)
Expand All @@ -170,8 +179,6 @@ function collectFiles(dir, id) {
}
})

CollectedFiles[dir] = result

return copyProps({}, result)
}

Expand Down Expand Up @@ -201,14 +208,8 @@ function writeModule(oFile, fileName, moduleId, debug) {
}

//------------------------------------------------------------------------------
var FileContents = {}

function getContents(file) {
if (!FileContents.hasOwnProperty(file)) {
FileContents[file] = fs.readFileSync(file, 'utf8')
}

return FileContents[file]
return fs.readFileSync(file, 'utf8');
}

//------------------------------------------------------------------------------
Expand Down
1 change: 0 additions & 1 deletion lib/test/plugin/android/nativeapiprovider.js

This file was deleted.

1 change: 0 additions & 1 deletion lib/test/plugin/android/promptbasednativeapi.js

This file was deleted.

17 changes: 13 additions & 4 deletions test/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,20 +105,29 @@ module.exports = {
connect.static(_path.join(__dirname, '..', 'thirdparty')),
connect.static(__dirname),
connect.router(function (app) {
app.get('/cordova.test.js', function (req, res) {
res.writeHead(200, {
"Cache-Control": "no-cache",
"Content-Type": "text/javascript"
});
res.end(packager.bundle('test'));
}),
app.get('/', function (req, res) {
res.writeHead(200, {
"Cache-Control": "no-cache",
"Content-Type": "text/html"
});

//create the script tags to include
tests = [];
collect(__dirname, tests);

specs = tests.map(function (file, path) {
return '<script src="' + file.replace(/^.*test/, "test") +
return '<script src="' + file.replace(/^.*\/test\//, "/") +
'" type="text/javascript" charset="utf-8"></script>';
}).join('');
modules = packager.bundle('test');
doc = html.replace(/<!-- ##TESTS## -->/g, specs).replace(/"##MODULES##"/g, modules);

//inject in the test script includes and write the document
doc = html.replace(/<!-- ##TESTS## -->/g, specs);
res.end(doc);
});
})
Expand Down
7 changes: 3 additions & 4 deletions test/suite.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,17 @@
})();
</script>

<script type="text/javascript" src="cordova.test.js"></script>

<script type="text/javascript">
"##MODULES##"
var define = cordova.define;
var require = cordova.require;
var define = cordova.define;
</script>

<!-- ##TESTS## -->

<!-- Note: if you want to run individual tests, remove the tests placeholder above and include the individual tests yourself -->

<!-- <script src="test.accelerometer.js" type="text/javascript" charset="utf-8"></script> -->

</head>

<body>
Expand Down

0 comments on commit e4561c4

Please sign in to comment.