Skip to content
Permalink
Browse files
added test cases for require() and friends
   https://issues.apache.org/jira/browse/CB-267

Added the commonjs test suite from:

   https://github.com/commonjs/commonjs

Those tests are now in

   thirdparty/commonjs-tests

Test scaffolding has been added to

   test/commonjs

See the README.txt file in that directory for
instructions on running the tests.

In addition, the LICENSE was modified to include
information on the commonjs tests and existing
jasmine usage.  A NOTICE file was also added,
since it was not available before.
  • Loading branch information
pmuellr committed Feb 20, 2012
1 parent 8513d59 commit d7341998e657598a8419aa421d84e5bebbb26494
Show file tree
Hide file tree
Showing 48 changed files with 777 additions and 3 deletions.
96 LICENSE
@@ -187,9 +187,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright 2011 Adobe
Copyright 2011 IBM Corporation
Copyright 2011 RIM
Copyright [yyyy] [name of copyright owner]

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@@ -203,3 +201,95 @@
See the License for the specific language governing permissions and
limitations under the License.

==============================================================
This product also include the following software:
==============================================================

--------------------------------------------------------------
jasmine from GitHub

https://github.com/pivotal/jasmine

MIT-style license

license available from:

https://github.com/pivotal/jasmine/blob/master/MIT.LICENSE

-----------------------------

Copyright (c) 2008-2011 Pivotal Labs

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


--------------------------------------------------------------
commonjs tests from the commonjs organization at GitHub

https://github.com/commonjs/commonjs

MIT-style license

license available from:

https://github.com/commonjs/commonjs/blob/master/docs/license.html.markdown

contributor list available from:

https://github.com/commonjs/commonjs/blob/master/docs/contributors.html.markdown

-----------------------------

Copyright 2009 Kevin Dangoor
Copyright 2009 Ihab Awad
Copyright 2009 Ash Berlin
Copyright 2009 Aristid Breitkreuz
Copyright 2009 Kevin Dangoor
Copyright 2009 Daniel Friesen
Copyright 2009 Wes Garland
Copyright 2009 Kris Kowal
Copyright 2009 Dean Landolt
Copyright 2009 Peter Michaux
Copyright 2009 George Moschovitis
Copyright 2009 Michael O'Brien
Copyright 2009 Tom Robinson
Copyright 2009 Hannes Wallnoefer
Copyright 2009 Mike Wilson
Copyright 2009 Ondrej Zara
Copyright 2009 Chris Zumbrunn
Copyright 2009 Kris Zyp

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
5 NOTICE
@@ -0,0 +1,5 @@
Apache Cordova weinre
Copyright 2012 The Apache Software Foundation

This product includes software developed at
The Apache Software Foundation (http://www.apache.org/).
@@ -0,0 +1 @@
out
@@ -0,0 +1,11 @@
This directory contains tests for the CommonJS functionality in Cordova.

The tests come from the GitHub project https://github.com/commonjs/commonjs

To run the tests, first you need to build them.

Open a shell, cd into this directory, and run `python build-tests.py`.

This will generate a set of HTML files which will run the tests within
a browser. More instructions on how to run the tests are printed
after the tests are built.
@@ -0,0 +1,196 @@
#!/usr/bin/env python

# ---
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you 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 os
import re
import sys
import shutil
import datetime
import subprocess

PROGRAM = sys.argv[0]

#-------------------------------------------------------------------------------
#
#-------------------------------------------------------------------------------
def main():

# all work done in directory of this program
baseDir = os.path.dirname(PROGRAM)
os.chdir(baseDir)

testsDir = os.path.abspath("../../thirdparty/commonjs-tests")
outDir = os.path.abspath("out")

# validate testsDir
if not os.path.exists(testsDir):
error("tests dir does not exist: %s" % testsDir)

if not os.path.isdir(testsDir):
error("tests dir is not a directory: %s" % testsDir)

# validate and reset outDir
if os.path.exists(outDir):
if not os.path.isdir(outDir):
error("out dir is not a directory: %s" % outDir)

shutil.rmtree(outDir)

os.makedirs(outDir)

tests = getTests(testsDir)

# now all work done in outDir
os.chdir("out")

# build the individual tests
iframes = []
for test in tests:
testName = test.replace('/', '-')
htmlFile = buildTest(os.path.join(testsDir, test), testName)
iframes.append("<iframe width='100%%' height='30' src='%s'></iframe>" % htmlFile)

iframesLines = "\n".join(iframes)

# build the browser launcher
html = fileContents("../launcher-main.template.html")

html = html.replace("@iframes@", iframesLines)
html = html.replace("@date@", getDate())

oFileName = "launcher-all.html"
oFile = file(oFileName, "w")
oFile.write(html)
oFile.close()

print
print "Generated browser test: %s" % os.path.abspath(oFileName)
print
print "You can run the test as a local file under Safari but not Chrome."
print "To test under Chrome, access the files via http://"

#-------------------------------------------------------------------------------
#
#-------------------------------------------------------------------------------
def buildTest(testDir, testName):

log("generating tests for %s" % (testName))

html = fileContents("../launcher-in-iframe.template.html")

# get the list of modules
modules = getModules(testDir)

modulesSource = []

modulesSource.append("try {")

for module in modules:
source = fileContents("%s.js" % os.path.join(testDir, module))

modulesSource.append("//----------------------------------------------")
modulesSource.append("define('%s', function(require,exports,module) {" % module)
modulesSource.append(source.strip())
modulesSource.append("});")
modulesSource.append("")

modulesSource.append("}")
modulesSource.append("catch(e) {")
modulesSource.append(" console.log('exception thrown loading modules: ' + e)")
modulesSource.append("}")

modulesLines = "\n".join(modulesSource)

html = html.replace("@modules@", modulesLines)
html = html.replace("@title@", testName)
html = html.replace("@date@", getDate())

# build HTML launcher for iframe
oFileName = "%s.html" % testName
oFile = file(oFileName, "w")
oFile.write(html)
oFile.close()

return oFileName

#-------------------------------------------------------------------------------
#
#-------------------------------------------------------------------------------
def getModules(testDir):
modules = []
for root, dirs, files in os.walk(testDir):
for file in files:
if not file.endswith(".js"): continue

moduleSource = os.path.relpath(os.path.join(root, file), testDir)
moduleName = os.path.splitext(moduleSource)[0]
modules.append(moduleName)

return modules

#-------------------------------------------------------------------------------
#
#-------------------------------------------------------------------------------
def getTests(testDir):
tests = []
for root, dirs, files in os.walk(testDir):
if "program.js" in files:
tests.append(os.path.relpath(root, testDir))

return tests

#-------------------------------------------------------------------------------
#
#-------------------------------------------------------------------------------
def run(cmdArgs):
result = subprocess.Popen(cmdArgs, stdout=subprocess.PIPE).communicate()[0]
if not re.match(r"\s*", result):
print result

#-------------------------------------------------------------------------------
#
#-------------------------------------------------------------------------------
def fileContents(iFileName):
iFile = file(iFileName)
contents = iFile.read()
iFile.close()

return contents

def getDate():
return datetime.datetime.today().isoformat(" ")
#-------------------------------------------------------------------------------
#
#-------------------------------------------------------------------------------
def log(message):
print "%s: %s" % (PROGRAM, message)

#-------------------------------------------------------------------------------
#
#-------------------------------------------------------------------------------
def error(message):
log(message)
exit(1)

#-------------------------------------------------------------------------------
#
#-------------------------------------------------------------------------------
main()

0 comments on commit d734199

Please sign in to comment.