本文整理匯總了TypeScript中src/lib/executors/Executor.LoaderInit.default方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript LoaderInit.default方法的具體用法?TypeScript LoaderInit.default怎麽用?TypeScript LoaderInit.default使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類src/lib/executors/Executor.LoaderInit
的用法示例。
在下文中一共展示了LoaderInit.default方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: registerSuite
registerSuite('loaders/default', function() {
let removeMocks: () => void;
const mockIntern = {
config: { basePath: '/' },
emit: spy(() => {}),
loadScript: stub().resolves(),
registerLoader: spy((_init: LoaderInit) => {}),
log: spy(() => {})
};
return {
before() {
global.intern = mockIntern;
return mockRequire(
require,
'src/loaders/default',
{}
).then(handle => {
removeMocks = handle.remove;
assert.equal(mockIntern.registerLoader.callCount, 1);
});
},
after() {
global.intern = originalIntern;
removeMocks();
},
beforeEach() {
global.intern = mockIntern;
mockIntern.emit.reset();
mockIntern.loadScript.reset();
mockIntern.loadScript.resolves();
},
afterEach() {
global.intern = originalIntern;
global.require = originalRequire;
},
tests: {
init() {
const init = mockIntern.registerLoader.getCall(0).args[0];
return Promise.resolve(init({})).then(() => {
// The default loader doesn't do anythign in its init
// function
assert.equal(mockIntern.loadScript.callCount, 0);
});
},
'load Modules'() {
const init: LoaderInit = mockIntern.registerLoader.getCall(0)
.args[0];
return Promise.resolve(init({})).then(loader => {
return loader(['foo.js']).then(() => {
assert.equal(mockIntern.loadScript.callCount, 1);
assert.equal(
mockIntern.loadScript.getCall(0).args[0],
'foo.js'
);
});
});
},
error() {
const init: LoaderInit = mockIntern.registerLoader.getCall(0)
.args[0];
mockIntern.loadScript.rejects(new Error('fail'));
return Promise.resolve(init({})).then(loader => {
return loader(['foo.js']).then(
() => {
throw new Error('should not have succeeded');
},
error => {
assert.match(error.message, /fail/);
}
);
});
}
}
};
});
示例2: mockRequire
registerSuite('loaders/systemjs', function() {
let removeMocks: () => void;
const mockIntern = {
// Use whatever the local environment is
environment: intern.environment,
config: { basePath: '/' },
emit: spy(() => {}),
loadScript: spy(() => Promise.resolve()),
registerLoader: spy((_init: LoaderInit) => {}),
log: spy(() => {})
};
const fakeRequire: any = spy((_module: string) => {
return mockSystemJS;
});
const mockSystemJS = {
config: spy(() => {}),
import: stub().resolves()
};
return {
before() {
global.intern = mockIntern;
return mockRequire(
require,
'src/loaders/systemjs',
{}
).then(handle => {
removeMocks = handle.remove;
assert.equal(mockIntern.registerLoader.callCount, 1);
});
},
after() {
global.intern = originalIntern;
removeMocks();
},
beforeEach() {
global.intern = mockIntern;
global.require = fakeRequire;
global.SystemJS = mockSystemJS;
mockIntern.emit.reset();
mockIntern.loadScript.reset();
fakeRequire.reset();
},
afterEach() {
global.intern = originalIntern;
global.require = originalRequire;
global.SystemJS = originalSystemJS;
},
tests: {
init() {
const init = mockIntern.registerLoader.getCall(0).args[0];
return Promise.resolve(init({})).then(() => {
if (intern.environment === 'browser') {
assert.equal(mockIntern.loadScript.callCount, 1);
}
});
},
'load Modules'() {
const init: LoaderInit = mockIntern.registerLoader.getCall(0)
.args[0];
return Promise.resolve(init({})).then(loader => {
return loader(['foo.js']).then(() => {
assert.equal(mockSystemJS.import.callCount, 1);
assert.deepEqual(
mockSystemJS.import.getCall(0).args[0],
'foo.js'
);
});
});
},
error() {
const init: LoaderInit = mockIntern.registerLoader.getCall(0)
.args[0];
return Promise.resolve(init({})).then(loader => {
const error = new Error('fail');
mockSystemJS.import.callsFake(() => Promise.reject(error));
return loader(['foo.js']).then(
() => {
throw new Error('should not have succeeded');
},
error => {
assert.match(error.message, /fail/);
}
);
});
}
}
};
});
示例3: mockRequire
registerSuite('loaders/esm', () => {
const sandbox = Sandbox.create();
let removeMocks: () => void;
let init: LoaderInit;
const mockIntern = {
environment: 'browser',
config: { basePath: '/' },
emit: sandbox.spy(() => {}),
loadScript: sandbox.stub().resolves(),
registerLoader: sandbox.spy((_init: LoaderInit) => {}),
log: sandbox.spy(() => {})
};
return {
before() {
global.intern = mockIntern;
return mockRequire(require, 'src/loaders/esm', {}).then(handle => {
removeMocks = handle.remove;
assert.equal(mockIntern.registerLoader.callCount, 1);
init = mockIntern.registerLoader.args[0][0];
});
},
after() {
removeMocks();
},
beforeEach() {
global.intern = mockIntern;
},
afterEach() {
global.intern = originalIntern;
sandbox.resetHistory();
mockIntern.environment = 'browser';
},
tests: {
init: {
normal() {
return Promise.resolve(init({})).then(() => {
assert.equal(mockIntern.loadScript.callCount, 0);
});
},
'non-browser'() {
mockIntern.environment = 'node';
assert.throws(() => {
init({});
}, /The ESM loader only works in the browser/);
}
},
'load Modules'() {
return Promise.resolve(init({})).then(loader => {
return loader(['foo.js']).then(() => {
assert.equal(mockIntern.loadScript.callCount, 1);
assert.deepEqual(mockIntern.loadScript.getCall(0).args, [
['foo.js'],
true
]);
});
});
},
error() {
mockIntern.loadScript.rejects(new Error('fail'));
return Promise.resolve(init({})).then(loader => {
return loader(['foo.js']).then(
() => {
throw new Error('should not have succeeded');
},
error => {
assert.match(error.message, /fail/);
}
);
});
}
}
};
});
示例4: mockRequire
registerSuite('loaders/dojo2', function() {
let removeMocks: () => void;
const mockIntern = {
config: { basePath: '/' },
emit: spy(() => {}),
loadScript: spy(() => Promise.resolve()),
registerLoader: spy((_init: LoaderInit) => {}),
log: spy(() => {})
};
const fakeRequire: any = spy((_modules: string[], callback: () => void) => {
if (requirePromise) {
requirePromise.then(callback);
} else {
callback();
}
});
fakeRequire.on = spy(() => {
return { remove() {} };
});
fakeRequire.config = spy(() => {});
let requirePromise: Promise<void>;
return {
before() {
global.intern = mockIntern;
return mockRequire(
require,
'src/loaders/dojo2',
{}
).then(handle => {
removeMocks = handle.remove;
assert.equal(mockIntern.registerLoader.callCount, 1);
});
},
after() {
global.intern = originalIntern;
removeMocks();
},
beforeEach() {
global.intern = mockIntern;
global.require = fakeRequire;
mockIntern.emit.reset();
mockIntern.loadScript.reset();
fakeRequire.reset();
fakeRequire.on.reset();
fakeRequire.config.reset();
},
afterEach() {
global.intern = originalIntern;
global.dojoConfig = originalDojoConfig;
global.require = originalRequire;
},
tests: {
init() {
const init = mockIntern.registerLoader.getCall(0).args[0];
return init({}).then(() => {
assert.equal(mockIntern.loadScript.callCount, 1);
});
},
'load Modules'() {
const init: LoaderInit = mockIntern.registerLoader.getCall(0)
.args[0];
return Promise.resolve(init({})).then(loader => {
return loader(['foo.js']).then(() => {
assert.equal(fakeRequire.callCount, 1);
assert.deepEqual(fakeRequire.getCall(0).args[0], [
'foo.js'
]);
});
});
},
error() {
const init: LoaderInit = mockIntern.registerLoader.getCall(0)
.args[0];
return Promise.resolve(init({})).then(loader => {
requirePromise = new Promise<void>(() => {});
const error = new Error('fail');
setTimeout(() => {
assert.equal(
fakeRequire.on.getCall(0).args[0],
'error'
);
const errorHandler = fakeRequire.on.getCall(0).args[1];
errorHandler(error);
});
return loader(['foo.js']).then(
() => {
throw new Error('should not have succeeded');
},
//.........這裏部分代碼省略.........
示例5: init
assert.throws(() => {
init({});
}, /The ESM loader only works in the browser/);