This repository has been archived by the owner on Jul 30, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add unit tests and improve implementation based on the results
- Loading branch information
1 parent
1dd74d0
commit b6b4648
Showing
7 changed files
with
88 additions
and
19 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,54 @@ | ||
import assert = require('intern/chai!assert'); | ||
import registerSuite = require('intern!object'); | ||
import has from 'src/has'; | ||
import load from 'src/load'; | ||
import Promise from 'src/Promise'; | ||
|
||
const suite: any = { | ||
name: 'load', | ||
|
||
load() { | ||
var def = this.async(5000); | ||
|
||
load(require, './load/a', './load/b').then(def.callback(function ([ a, b ]: [ any, any ]) { | ||
assert.deepEqual(a, { one: 1, two: 2 }); | ||
assert.deepEqual(b, { three: 3, four: 4 }); | ||
})); | ||
} | ||
}; | ||
|
||
if (has('host-node')) { | ||
const nodeRequire: any = global.require.nodeRequire; | ||
const path: any = nodeRequire('path'); | ||
const buildDir: string = path.join(process.cwd(), '_build'); | ||
|
||
suite.node = { | ||
'different than AMD load'() { | ||
const nodeLoad: typeof load = nodeRequire(path.join(buildDir, 'src', 'load')).default; | ||
assert.notStrictEqual(nodeLoad, load); | ||
}, | ||
|
||
'load succeeds'() { | ||
var def = this.async(5000); | ||
|
||
var result: Promise<any[]> = nodeRequire(path.join(buildDir, 'tests', 'unit', 'load', 'node')).succeed; | ||
result.then(def.callback(function ([ a, b ]: [ any, any ]) { | ||
assert.deepEqual(a, { one: 1, two: 2 }); | ||
assert.deepEqual(b, { three: 3, four: 4 }); | ||
})); | ||
}, | ||
|
||
'load fails'() { | ||
var def = this.async(5000); | ||
|
||
var result: Promise<any[]> = nodeRequire(path.join(buildDir, 'tests', 'unit', 'load', 'node')).fail; | ||
result.then(function () { | ||
def.reject(new Error('load should not have succeeded')); | ||
}, def.callback(function (error: Error) { | ||
assert.instanceOf(error, Error); | ||
})); | ||
} | ||
}; | ||
} | ||
|
||
registerSuite(suite); |
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,2 @@ | ||
export const one = 1; | ||
export const two = 2; |
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,2 @@ | ||
export const three = 3; | ||
export const four = 4; |
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,4 @@ | ||
import load from '../../../src/load'; | ||
|
||
export const succeed = load(require, './a', './b'); | ||
export const fail = load(require, './a', './c'); |
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