Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions optional.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
"use strict";
try {
module.exports = require('./register')().Promise || null
} catch(e) {
module.exports = null
}
13 changes: 13 additions & 0 deletions test-browser/optional.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
'use strict';
window.Promise = undefined
var assert = require('assert')

it('Optional test in browser', function(){
var Promise = require('../optional')
assert.ok(!Promise)
assert.throws(function(){
var Promise = require('../')
}, 'Expecting bare require to throw ');
Promise = require('../optional')
assert.ok(!Promise)
})
2 changes: 1 addition & 1 deletion test/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var {spawn} = require('child_process')
if (+version[1] <= 5) {
test('skipped browser tests for Node.js <= 5', () => {})
} else {
;['register', 'local', 'polyfill', 'shortcut'].forEach(filename => {
;['register', 'local', 'polyfill', 'optional', 'shortcut'].forEach(filename => {
test.serial('Browser test: '+filename, () => zuul(filename))
})
}
Expand Down
11 changes: 11 additions & 0 deletions test/optional.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
var test = require('ava')
var Promise = require('../optional')
var isPromise = require('is-promise')

test(t => {
// optional should always be defined based on current setup.
t.is(Promise, global.Promise)
t.truthy(isPromise(new Promise(() => {})))
t.truthy(Promise.all)
t.truthy(global['@@any-promise/REGISTRATION'].implementation)
})