Esempio n. 1
0
export function getConfig(
  fileOrArgv?: string | string[],
  argv?: string[]
): CancellablePromise<{ config: any; file?: string }> {
  let args: { [key: string]: any } = {};
  let file = typeof fileOrArgv === 'string' ? fileOrArgv : undefined;
  argv = Array.isArray(fileOrArgv) ? fileOrArgv : argv;
  const userArgs = (argv || process.argv).slice(2);

  if (process.env['INTERN_ARGS']) {
    Object.assign(args, parseArgs(parse(process.env['INTERN_ARGS'] || '')));
  }

  if (userArgs.length > 0) {
    Object.assign(args, parseArgs(userArgs));
  }

  if (file) {
    args.config = file;
  }

  let load: CancellablePromise<{ [key: string]: any }>;

  if (args.config) {
    // If a config parameter was provided, load it and mix in any other
    // command line args.
    const { configFile, childConfig } = splitConfigPath(args.config, sep);
    file = resolve(configFile || 'intern.json');
    load = loadConfig(file, loadText, args, childConfig);
  } else {
    // If no config parameter was provided, try 'intern.json', or just
    // resolve to the original args
    file = resolve('intern.json');
    load = loadConfig(file, loadText, args, undefined).catch(
      (error: NodeJS.ErrnoException) => {
        if (error.code === 'ENOENT') {
          file = undefined;
          return args;
        }
        throw error;
      }
    );
  }

  return load
    .then(config => {
      // If a basePath wasn't set in the config or via a query arg, and we
      // have a config file path, use that.
      if (file) {
        config.basePath = getBasePath(file, config.basePath, isAbsolute, sep);
      }
      return config;
    })
    .then(config => ({ config, file }));
}
Esempio n. 2
0
  protected _sendData(name: string, data: any) {
    return this._ready.then(
      () =>
        new Task<void>((resolve, reject) => {
          const id = String(this._sequence++);
          const sessionId = this.sessionId;
          const message: Message = { id, sessionId, name, data };

          this._socket.send(JSON.stringify(message));

          const timer = setTimeout(() => {
            reject(new Error('Send timed out'));
          }, this.timeout);

          this._sendQueue[id] = {
            resolve(data: any) {
              clearTimeout(timer);
              resolve(data);
            },
            reject(error: Error) {
              reject(error);
            }
          };
        })
    );
  }
Esempio n. 3
0
export function getConfig(file?: string) {
  const args = parseArgs(parseQuery());
  const configBase = getDefaultBasePath();
  if (file) {
    args.config = file;
  }

  let load: CancellablePromise<{ [key: string]: any }>;

  if (args.config) {
    // If a config parameter was provided, load it, mix in any other query
    // params, then initialize the executor with that
    const { configFile, childConfig } = splitConfigPath(args.config);
    file = resolvePath(configFile || 'intern.json', configBase);
    load = loadConfig(file, loadText, args, childConfig);
  } else {
    // If no config parameter was provided, try 'intern.json'. If that file
    // doesn't exist, just return the args
    file = resolvePath('intern.json', configBase);
    load = loadConfig(file, loadText, args).catch(error => {
      if (error.message.indexOf('Request failed') === 0) {
        // The file wasn't found, clear the file name
        file = undefined;
        return args;
      }
      throw error;
    });
  }

  return load
    .then(config => {
      // If a basePath wasn't set in the config or via a query arg, and we
      // have a config file path, use that.
      if (file) {
        config.basePath = getBasePath(
          file,
          config.basePath,
          path => path[0] === '/',
          '/'
        );
      }
      return config;
    })
    .then(config => ({ config, file }));
}
Esempio n. 4
0
      (resolve, reject) => {
        this._messageBuffer.push({
          message: JSON.stringify(message),
          resolve,
          reject
        });

        if (this._activeRequest) {
          this._activeRequest.then(() => this._sendMessages());
        } else {
          this._sendMessages();
        }
      },
Esempio n. 5
0
 () => {
   if (this._activeRequest) {
     this._activeRequest.cancel();
   }
   this._messageBuffer = [];
 }