Skip to content

Commit d734199

Browse files
committed
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.
1 parent 8513d59 commit d734199

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+777
-3
lines changed

LICENSE

+93-3
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,7 @@
187187
same "printed page" as the copyright notice for easier
188188
identification within third-party archives.
189189

190-
Copyright 2011 Adobe
191-
Copyright 2011 IBM Corporation
192-
Copyright 2011 RIM
190+
Copyright [yyyy] [name of copyright owner]
193191

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

204+
==============================================================
205+
This product also include the following software:
206+
==============================================================
207+
208+
--------------------------------------------------------------
209+
jasmine from GitHub
210+
211+
https://github.com/pivotal/jasmine
212+
213+
MIT-style license
214+
215+
license available from:
216+
217+
https://github.com/pivotal/jasmine/blob/master/MIT.LICENSE
218+
219+
-----------------------------
220+
221+
Copyright (c) 2008-2011 Pivotal Labs
222+
223+
Permission is hereby granted, free of charge, to any person obtaining
224+
a copy of this software and associated documentation files (the
225+
"Software"), to deal in the Software without restriction, including
226+
without limitation the rights to use, copy, modify, merge, publish,
227+
distribute, sublicense, and/or sell copies of the Software, and to
228+
permit persons to whom the Software is furnished to do so, subject to
229+
the following conditions:
230+
231+
The above copyright notice and this permission notice shall be
232+
included in all copies or substantial portions of the Software.
233+
234+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
235+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
236+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
237+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
238+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
239+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
240+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
241+
242+
243+
--------------------------------------------------------------
244+
commonjs tests from the commonjs organization at GitHub
245+
246+
https://github.com/commonjs/commonjs
247+
248+
MIT-style license
249+
250+
license available from:
251+
252+
https://github.com/commonjs/commonjs/blob/master/docs/license.html.markdown
253+
254+
contributor list available from:
255+
256+
https://github.com/commonjs/commonjs/blob/master/docs/contributors.html.markdown
257+
258+
-----------------------------
259+
260+
Copyright 2009 Kevin Dangoor
261+
Copyright 2009 Ihab Awad
262+
Copyright 2009 Ash Berlin
263+
Copyright 2009 Aristid Breitkreuz
264+
Copyright 2009 Kevin Dangoor
265+
Copyright 2009 Daniel Friesen
266+
Copyright 2009 Wes Garland
267+
Copyright 2009 Kris Kowal
268+
Copyright 2009 Dean Landolt
269+
Copyright 2009 Peter Michaux
270+
Copyright 2009 George Moschovitis
271+
Copyright 2009 Michael O'Brien
272+
Copyright 2009 Tom Robinson
273+
Copyright 2009 Hannes Wallnoefer
274+
Copyright 2009 Mike Wilson
275+
Copyright 2009 Ondrej Zara
276+
Copyright 2009 Chris Zumbrunn
277+
Copyright 2009 Kris Zyp
278+
279+
Permission is hereby granted, free of charge, to any person obtaining a copy
280+
of this software and associated documentation files (the "Software"), to deal
281+
in the Software without restriction, including without limitation the rights
282+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
283+
copies of the Software, and to permit persons to whom the Software is
284+
furnished to do so, subject to the following conditions:
285+
286+
The above copyright notice and this permission notice shall be included in
287+
all copies or substantial portions of the Software.
288+
289+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
290+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
291+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
292+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
293+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
294+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
295+
THE SOFTWARE.

NOTICE

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Apache Cordova weinre
2+
Copyright 2012 The Apache Software Foundation
3+
4+
This product includes software developed at
5+
The Apache Software Foundation (http://www.apache.org/).

test/commonjs/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
out

test/commonjs/README.txt

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
This directory contains tests for the CommonJS functionality in Cordova.
2+
3+
The tests come from the GitHub project https://github.com/commonjs/commonjs
4+
5+
To run the tests, first you need to build them.
6+
7+
Open a shell, cd into this directory, and run `python build-tests.py`.
8+
9+
This will generate a set of HTML files which will run the tests within
10+
a browser. More instructions on how to run the tests are printed
11+
after the tests are built.

test/commonjs/build-tests.py

+196
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
#!/usr/bin/env python
2+
3+
# ---
4+
# Licensed to the Apache Software Foundation (ASF) under one
5+
# or more contributor license agreements. See the NOTICE file
6+
# distributed with this work for additional information
7+
# regarding copyright ownership. The ASF licenses this file
8+
# to you under the Apache License, Version 2.0 (the
9+
# "License"); you may not use this file except in compliance
10+
# with the License. You may obtain a copy of the License at
11+
#
12+
# http://www.apache.org/licenses/LICENSE-2.0
13+
#
14+
# Unless required by applicable law or agreed to in writing,
15+
# software distributed under the License is distributed on an
16+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17+
# KIND, either express or implied. See the License for the
18+
# specific language governing permissions and limitations
19+
# under the License.
20+
# ---
21+
22+
import os
23+
import re
24+
import sys
25+
import shutil
26+
import datetime
27+
import subprocess
28+
29+
PROGRAM = sys.argv[0]
30+
31+
#-------------------------------------------------------------------------------
32+
#
33+
#-------------------------------------------------------------------------------
34+
def main():
35+
36+
# all work done in directory of this program
37+
baseDir = os.path.dirname(PROGRAM)
38+
os.chdir(baseDir)
39+
40+
testsDir = os.path.abspath("../../thirdparty/commonjs-tests")
41+
outDir = os.path.abspath("out")
42+
43+
# validate testsDir
44+
if not os.path.exists(testsDir):
45+
error("tests dir does not exist: %s" % testsDir)
46+
47+
if not os.path.isdir(testsDir):
48+
error("tests dir is not a directory: %s" % testsDir)
49+
50+
# validate and reset outDir
51+
if os.path.exists(outDir):
52+
if not os.path.isdir(outDir):
53+
error("out dir is not a directory: %s" % outDir)
54+
55+
shutil.rmtree(outDir)
56+
57+
os.makedirs(outDir)
58+
59+
tests = getTests(testsDir)
60+
61+
# now all work done in outDir
62+
os.chdir("out")
63+
64+
# build the individual tests
65+
iframes = []
66+
for test in tests:
67+
testName = test.replace('/', '-')
68+
htmlFile = buildTest(os.path.join(testsDir, test), testName)
69+
iframes.append("<iframe width='100%%' height='30' src='%s'></iframe>" % htmlFile)
70+
71+
iframesLines = "\n".join(iframes)
72+
73+
# build the browser launcher
74+
html = fileContents("../launcher-main.template.html")
75+
76+
html = html.replace("@iframes@", iframesLines)
77+
html = html.replace("@date@", getDate())
78+
79+
oFileName = "launcher-all.html"
80+
oFile = file(oFileName, "w")
81+
oFile.write(html)
82+
oFile.close()
83+
84+
print
85+
print "Generated browser test: %s" % os.path.abspath(oFileName)
86+
print
87+
print "You can run the test as a local file under Safari but not Chrome."
88+
print "To test under Chrome, access the files via http://"
89+
90+
#-------------------------------------------------------------------------------
91+
#
92+
#-------------------------------------------------------------------------------
93+
def buildTest(testDir, testName):
94+
95+
log("generating tests for %s" % (testName))
96+
97+
html = fileContents("../launcher-in-iframe.template.html")
98+
99+
# get the list of modules
100+
modules = getModules(testDir)
101+
102+
modulesSource = []
103+
104+
modulesSource.append("try {")
105+
106+
for module in modules:
107+
source = fileContents("%s.js" % os.path.join(testDir, module))
108+
109+
modulesSource.append("//----------------------------------------------")
110+
modulesSource.append("define('%s', function(require,exports,module) {" % module)
111+
modulesSource.append(source.strip())
112+
modulesSource.append("});")
113+
modulesSource.append("")
114+
115+
modulesSource.append("}")
116+
modulesSource.append("catch(e) {")
117+
modulesSource.append(" console.log('exception thrown loading modules: ' + e)")
118+
modulesSource.append("}")
119+
120+
modulesLines = "\n".join(modulesSource)
121+
122+
html = html.replace("@modules@", modulesLines)
123+
html = html.replace("@title@", testName)
124+
html = html.replace("@date@", getDate())
125+
126+
# build HTML launcher for iframe
127+
oFileName = "%s.html" % testName
128+
oFile = file(oFileName, "w")
129+
oFile.write(html)
130+
oFile.close()
131+
132+
return oFileName
133+
134+
#-------------------------------------------------------------------------------
135+
#
136+
#-------------------------------------------------------------------------------
137+
def getModules(testDir):
138+
modules = []
139+
for root, dirs, files in os.walk(testDir):
140+
for file in files:
141+
if not file.endswith(".js"): continue
142+
143+
moduleSource = os.path.relpath(os.path.join(root, file), testDir)
144+
moduleName = os.path.splitext(moduleSource)[0]
145+
modules.append(moduleName)
146+
147+
return modules
148+
149+
#-------------------------------------------------------------------------------
150+
#
151+
#-------------------------------------------------------------------------------
152+
def getTests(testDir):
153+
tests = []
154+
for root, dirs, files in os.walk(testDir):
155+
if "program.js" in files:
156+
tests.append(os.path.relpath(root, testDir))
157+
158+
return tests
159+
160+
#-------------------------------------------------------------------------------
161+
#
162+
#-------------------------------------------------------------------------------
163+
def run(cmdArgs):
164+
result = subprocess.Popen(cmdArgs, stdout=subprocess.PIPE).communicate()[0]
165+
if not re.match(r"\s*", result):
166+
print result
167+
168+
#-------------------------------------------------------------------------------
169+
#
170+
#-------------------------------------------------------------------------------
171+
def fileContents(iFileName):
172+
iFile = file(iFileName)
173+
contents = iFile.read()
174+
iFile.close()
175+
176+
return contents
177+
178+
def getDate():
179+
return datetime.datetime.today().isoformat(" ")
180+
#-------------------------------------------------------------------------------
181+
#
182+
#-------------------------------------------------------------------------------
183+
def log(message):
184+
print "%s: %s" % (PROGRAM, message)
185+
186+
#-------------------------------------------------------------------------------
187+
#
188+
#-------------------------------------------------------------------------------
189+
def error(message):
190+
log(message)
191+
exit(1)
192+
193+
#-------------------------------------------------------------------------------
194+
#
195+
#-------------------------------------------------------------------------------
196+
main()

0 commit comments

Comments
 (0)