Runner.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import { test } from 'ava';
  2. import { Runner } from '../';
  3. import { spawnAsync } from '../dist/lib/util';
  4. const dir = './assets/project/';
  5. // FIXME: When run with other tests, the code will be 0.
  6. test.serial('commandline --mirror', async (t) => {
  7. const mirror = process.env.CI ? '' : '--mirror https://npm.taobao.org/mirrors/nwjs/';
  8. const { code, signal } = await spawnAsync('node', `./dist/bin/run.js ${ mirror } ${ dir } 233`.split(' '), {
  9. stdio: 'inherit',
  10. });
  11. t.is(code, 233);
  12. });
  13. test.serial('commandline with environment variables', async (t) => {
  14. const { code, signal } = await spawnAsync('node', `./dist/bin/run.js ${ dir } 233`.split(' '), {
  15. stdio: 'inherit',
  16. env: Object.assign({}, process.env, {
  17. NWJS_MIRROR: process.env.CI ? '' : 'https://npm.taobao.org/mirrors/nwjs/',
  18. }),
  19. });
  20. t.is(code, 233);
  21. });
  22. test.serial('commandline --detached', async (t) => {
  23. const mirror = process.env.CI ? '' : '--mirror https://npm.taobao.org/mirrors/nwjs/';
  24. const { code, signal } = await spawnAsync('node', `./dist/bin/run.js ${ mirror } --detached ${ dir } 233`.split(' '), {
  25. stdio: 'inherit',
  26. });
  27. t.is(code, 0);
  28. });
  29. test.serial('module', async (t) => {
  30. const mirror = process.env.CI ? undefined : 'https://npm.taobao.org/mirrors/nwjs/';
  31. const runner = new Runner({
  32. mirror,
  33. }, [ dir, '233' ]);
  34. const code = await runner.run();
  35. t.is(code, 233);
  36. });