-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make require() compliant with CommonJS Modules/1.1
- Loading branch information
Showing
34 changed files
with
546 additions
and
37 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
title: GettingStarted | ||
|
||
This wiki instance contains the CommonJS Modules/1.0 unit tests. | ||
|
||
To run them, open a console repl and execute "$tw.modules.execute('allTests')" there. You should see no exceptions or output starting with "FAIL" in the console. | ||
|
||
|
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,11 @@ | ||
/*\ | ||
title: absolute/b.js | ||
type: application/javascript | ||
module-type: library | ||
Absolute require test | ||
\*/ | ||
|
||
|
||
exports.foo = function() {}; |
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,16 @@ | ||
/*\ | ||
title: absolute/program.js | ||
type: application/javascript | ||
module-type: library | ||
Absolute require test | ||
\*/ | ||
|
||
|
||
var test = require('test'); | ||
var a = require('./submodule/a'); | ||
var b = require('./b'); | ||
test.assert(a.foo().foo === b.foo, 'require works with absolute identifiers'); | ||
test.print('DONE', 'info'); | ||
|
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,14 @@ | ||
/*\ | ||
title: absolute/submodule/a.js | ||
type: application/javascript | ||
module-type: library | ||
Absolute require test | ||
\*/ | ||
|
||
|
||
exports.foo = function () { | ||
return require('../b'); | ||
}; | ||
|
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,23 @@ | ||
/*\ | ||
title: allTests.js | ||
type: application/javascript | ||
module-type: library | ||
Runs all CommonJS Modules tests | ||
\*/ | ||
|
||
$tw.modules.execute('absolute/program.js'); | ||
$tw.modules.execute('cyclic/program.js'); | ||
$tw.modules.execute('determinism/program.js'); | ||
$tw.modules.execute('exactExports/program.js'); | ||
$tw.modules.execute('hasOwnProperty/program.js'); | ||
$tw.modules.execute('method/program.js'); | ||
$tw.modules.execute('missing/program.js'); | ||
$tw.modules.execute('monkeys/program.js'); | ||
$tw.modules.execute('nested/program.js'); | ||
$tw.modules.execute('relative/program.js'); | ||
$tw.modules.execute('transitive/program.js'); | ||
|
||
|
||
|
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,15 @@ | ||
/*\ | ||
title: cyclic/a.js | ||
type: application/javascript | ||
module-type: library | ||
Cycle require test A | ||
\*/ | ||
|
||
exports.a = function () { | ||
return b; | ||
}; | ||
var b = require('./b'); | ||
|
||
|
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,16 @@ | ||
/*\ | ||
title: cyclic/b.js | ||
type: application/javascript | ||
module-type: library | ||
Cycle require test B | ||
\*/ | ||
|
||
|
||
|
||
var a = require('./a'); | ||
exports.b = function () { | ||
return a; | ||
}; | ||
|
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,22 @@ | ||
/*\ | ||
title: cyclic/program.js | ||
type: application/javascript | ||
module-type: library | ||
Cycle require test | ||
\*/ | ||
|
||
|
||
|
||
var test = require('test'); | ||
var a = require('./a'); | ||
var b = require('./b'); | ||
|
||
test.assert(a.a, 'a exists'); | ||
test.assert(b.b, 'b exists') | ||
test.assert(a.a().b === b.b, 'a gets b'); | ||
test.assert(b.b().a === a.a, 'b gets a'); | ||
|
||
test.print('DONE', 'info'); | ||
|
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,14 @@ | ||
/*\ | ||
title: determinism/program.js | ||
type: application/javascript | ||
module-type: library | ||
Determinism test | ||
\*/ | ||
|
||
|
||
var test = require('test'); | ||
require('submodule/a'); | ||
test.print('DONE', 'info'); | ||
|
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,20 @@ | ||
/*\ | ||
title: determinism/submodule/a.js | ||
type: application/javascript | ||
module-type: library | ||
Determinism require test A | ||
\*/ | ||
|
||
|
||
var test = require('test'); | ||
var pass = false; | ||
var test = require('test'); | ||
try { | ||
require('a'); | ||
} catch (exception) { | ||
pass = true; | ||
} | ||
test.assert(pass, 'require does not fall back to relative modules when absolutes are not available.') | ||
|
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,15 @@ | ||
/*\ | ||
title: exactExports/a.js | ||
type: application/javascript | ||
module-type: library | ||
ExactExports test A | ||
\*/ | ||
|
||
|
||
exports.program = function () { | ||
return require('./program'); | ||
}; | ||
|
||
|
Oops, something went wrong.