當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。