当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript Executor.LoaderInit类代码示例

本文整理汇总了TypeScript中src/lib/executors/Executor.LoaderInit的典型用法代码示例。如果您正苦于以下问题:TypeScript LoaderInit类的具体用法?TypeScript LoaderInit怎么用?TypeScript LoaderInit使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了LoaderInit类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: registerSuite

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/);
						}
					);
				});
			}
		}
	};
});
开发者ID:jason0x43,项目名称:intern,代码行数:99,代码来源:systemjs.ts

示例2: registerSuite

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/);
            }
          );
        });
      }
    }
  };
});
开发者ID:edhager,项目名称:intern,代码行数:82,代码来源:esm.ts

示例3: registerSuite

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');
						},
//.........这里部分代码省略.........
开发者ID:devpaul,项目名称:intern,代码行数:101,代码来源:dojo2.ts

示例4: 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/);
						}
					);
				});
			}
		}
	};
});
开发者ID:jason0x43,项目名称:intern,代码行数:83,代码来源:default.ts

示例5: init

 assert.throws(() => {
   init({});
 }, /The ESM loader only works in the browser/);
开发者ID:edhager,项目名称:intern,代码行数:3,代码来源:esm.ts


注:本文中的src/lib/executors/Executor.LoaderInit类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。