本文整理汇总了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/);