Skip to content

Commit 39a1034

Browse files
committed
Add optional import
- Fixes #15
1 parent 01ac9a3 commit 39a1034

File tree

4 files changed

+31
-1
lines changed

4 files changed

+31
-1
lines changed

optional.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
"use strict";
2+
try {
3+
module.exports = require('./register')().Promise || null
4+
} catch(e) {
5+
module.exports = null
6+
}

test-browser/optional.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
'use strict';
2+
window.Promise = undefined
3+
var assert = require('assert')
4+
5+
it('Optional test in browser', function(){
6+
var Promise = require('../optional')
7+
assert.ok(!Promise)
8+
assert.throws(function(){
9+
var Promise = require('../')
10+
}, 'Expecting bare require to throw ');
11+
Promise = require('../optional')
12+
assert.ok(!Promise)
13+
})

test/browser.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ var {spawn} = require('child_process')
66
if (+version[1] <= 5) {
77
test('skipped browser tests for Node.js <= 5', () => {})
88
} else {
9-
;['register', 'local', 'polyfill', 'shortcut'].forEach(filename => {
9+
;['register', 'local', 'polyfill', 'optional', 'shortcut'].forEach(filename => {
1010
test.serial('Browser test: '+filename, () => zuul(filename))
1111
})
1212
}

test/optional.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
var test = require('ava')
2+
var Promise = require('../optional')
3+
var isPromise = require('is-promise')
4+
5+
test(t => {
6+
// optional should always be defined based on current setup.
7+
t.is(Promise, global.Promise)
8+
t.truthy(isPromise(new Promise(() => {})))
9+
t.truthy(Promise.all)
10+
t.truthy(global['@@any-promise/REGISTRATION'].implementation)
11+
})

0 commit comments

Comments
 (0)