Skip to content

Commit

Permalink
Re-enable Windows in CI (#500)
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky authored May 18, 2022
1 parent a09cbc0 commit 071d0a2
Show file tree
Hide file tree
Showing 11 changed files with 44 additions and 32 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
os:
- ubuntu-latest
- macos-latest
# - windows-latest
- windows-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
"get-node": "^12.0.0",
"is-running": "^2.1.0",
"p-event": "^5.0.1",
"path-key": "^4.0.0",
"tempfile": "^4.0.0",
"tsd": "^0.19.1",
"xo": "^0.48.0"
Expand Down
6 changes: 2 additions & 4 deletions test/command.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import path from 'node:path';
import process from 'node:process';
import {fileURLToPath} from 'node:url';
import test from 'ava';
import {execa, execaSync, execaCommand, execaCommandSync} from '../index.js';
import {setFixtureDir} from './helpers/fixtures-dir.js';

process.env.PATH = fileURLToPath(new URL('fixtures', import.meta.url)) + path.delimiter + process.env.PATH;
setFixtureDir();

const command = async (t, expected, ...args) => {
const {command: failCommand} = await t.throwsAsync(execa('fail.js', args));
Expand Down
5 changes: 2 additions & 3 deletions test/error.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import path from 'node:path';
import process from 'node:process';
import childProcess from 'node:child_process';
import {fileURLToPath} from 'node:url';
import {promisify} from 'node:util';
import test from 'ava';
import {execa, execaSync} from '../index.js';
import {setFixtureDir} from './helpers/fixtures-dir.js';

const pExec = promisify(childProcess.exec);

process.env.PATH = fileURLToPath(new URL('fixtures', import.meta.url)) + path.delimiter + process.env.PATH;
setFixtureDir();

const TIMEOUT_REGEXP = /timed out after/;

Expand Down
14 changes: 14 additions & 0 deletions test/helpers/fixtures-dir.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import path from 'node:path';
import process from 'node:process';
import {fileURLToPath} from 'node:url';
import pathKey from 'path-key';

export const PATH_KEY = pathKey();
const FIXTURES_DIR = fileURLToPath(new URL('../fixtures', import.meta.url));

// Add the fixtures directory to PATH so fixtures can be executed without adding
// `node`. This is only meant to make writing tests simpler.
export const setFixtureDir = () => {
process.env[PATH_KEY] = FIXTURES_DIR + path.delimiter + process.env[PATH_KEY];
};

5 changes: 2 additions & 3 deletions test/kill.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import path from 'node:path';
import process from 'node:process';
import {fileURLToPath} from 'node:url';
import test from 'ava';
import {pEvent} from 'p-event';
import isRunning from 'is-running';
import {execa, execaSync} from '../index.js';
import {setFixtureDir} from './helpers/fixtures-dir.js';

process.env.PATH = fileURLToPath(new URL('fixtures', import.meta.url)) + path.delimiter + process.env.PATH;
setFixtureDir();

const TIMEOUT_REGEXP = /timed out after/;

Expand Down
5 changes: 2 additions & 3 deletions test/node.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import path from 'node:path';
import process from 'node:process';
import {fileURLToPath} from 'node:url';
import test from 'ava';
import {pEvent} from 'p-event';
import {execaNode} from '../index.js';
import {setFixtureDir} from './helpers/fixtures-dir.js';

process.env.PATH = fileURLToPath(new URL('fixtures', import.meta.url)) + path.delimiter + process.env.PATH;
setFixtureDir();

async function inspectMacro(t, input) {
const originalArgv = process.execArgv;
Expand Down
7 changes: 2 additions & 5 deletions test/override-promise.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import path from 'node:path';
import process from 'node:process';
import {fileURLToPath} from 'node:url';
import test from 'ava';
// The helper module overrides Promise on import so has to be imported before `execa`.
import {restorePromise} from './helpers/override-promise.js';
// eslint-disable-next-line import/order
import {execa} from '../index.js';
import {setFixtureDir} from './helpers/fixtures-dir.js';

restorePromise();

process.env.PATH = fileURLToPath(new URL('fixtures', import.meta.url)) + path.delimiter + process.env.PATH;
setFixtureDir();

test('should work with third-party Promise', async t => {
const {stdout} = await execa('noop.js', ['foo']);
Expand Down
6 changes: 2 additions & 4 deletions test/promise.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import path from 'node:path';
import process from 'node:process';
import {fileURLToPath} from 'node:url';
import test from 'ava';
import {execa} from '../index.js';
import {setFixtureDir} from './helpers/fixtures-dir.js';

process.env.PATH = fileURLToPath(new URL('fixtures', import.meta.url)) + path.delimiter + process.env.PATH;
setFixtureDir();

test('promise methods are not enumerable', t => {
const descriptors = Object.getOwnPropertyDescriptors(execa('noop.js'));
Expand Down
5 changes: 2 additions & 3 deletions test/stream.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import {Buffer} from 'node:buffer';
import path from 'node:path';
import process from 'node:process';
import fs from 'node:fs';
import {fileURLToPath} from 'node:url';
import Stream from 'node:stream';
import test from 'ava';
import getStream from 'get-stream';
import tempfile from 'tempfile';
import {execa, execaSync} from '../index.js';
import {setFixtureDir} from './helpers/fixtures-dir.js';

process.env.PATH = fileURLToPath(new URL('fixtures', import.meta.url)) + path.delimiter + process.env.PATH;
setFixtureDir();

test('buffer', async t => {
const {stdout} = await execa('noop.js', ['foo'], {encoding: null});
Expand Down
20 changes: 14 additions & 6 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import test from 'ava';
import isRunning from 'is-running';
import getNode from 'get-node';
import {execa, execaSync} from '../index.js';
import {setFixtureDir, PATH_KEY} from './helpers/fixtures-dir.js';

process.env.PATH = fileURLToPath(new URL('fixtures', import.meta.url)) + path.delimiter + process.env.PATH;
setFixtureDir();
process.env.FOO = 'foo';

const ENOENT_REGEXP = process.platform === 'win32' ? /failed with exit code 1/ : /spawn.* ENOENT/;
Expand Down Expand Up @@ -76,16 +77,23 @@ test('stripFinalNewline in sync mode on failure', t => {
t.is(stderr, 'foo');
});

const getPathWithoutLocalDir = () => {
const newPath = process.env[PATH_KEY].split(path.delimiter).filter(pathDir => !BIN_DIR_REGEXP.test(pathDir)).join(path.delimiter);
return {[PATH_KEY]: newPath};
};

const BIN_DIR_REGEXP = /node_modules[\\/]\.bin/;

test('preferLocal: true', async t => {
await t.notThrowsAsync(execa('ava', ['--version'], {preferLocal: true, env: {Path: '', PATH: ''}}));
await t.notThrowsAsync(execa('ava', ['--version'], {preferLocal: true, env: getPathWithoutLocalDir()}));
});

test('preferLocal: false', async t => {
await t.throwsAsync(execa('ava', ['--version'], {preferLocal: false, env: {Path: '', PATH: ''}}), {message: ENOENT_REGEXP});
await t.throwsAsync(execa('ava', ['--version'], {preferLocal: false, env: getPathWithoutLocalDir()}), {message: ENOENT_REGEXP});
});

test('preferLocal: undefined', async t => {
await t.throwsAsync(execa('ava', ['--version'], {env: {Path: '', PATH: ''}}), {message: ENOENT_REGEXP});
await t.throwsAsync(execa('ava', ['--version'], {env: getPathWithoutLocalDir()}), {message: ENOENT_REGEXP});
});

test('localDir option', async t => {
Expand Down Expand Up @@ -189,12 +197,12 @@ test('use environment variables by default', async t => {
});

test('extend environment variables by default', async t => {
const {stdout} = await execa('environment.js', [], {env: {BAR: 'bar'}});
const {stdout} = await execa('environment.js', [], {env: {BAR: 'bar', [PATH_KEY]: process.env[PATH_KEY]}});
t.deepEqual(stdout.split('\n'), ['foo', 'bar']);
});

test('do not extend environment with `extendEnv: false`', async t => {
const {stdout} = await execa('environment.js', [], {env: {BAR: 'bar', PATH: process.env.PATH}, extendEnv: false});
const {stdout} = await execa('environment.js', [], {env: {BAR: 'bar', [PATH_KEY]: process.env[PATH_KEY]}, extendEnv: false});
t.deepEqual(stdout.split('\n'), ['undefined', 'bar']);
});

Expand Down

0 comments on commit 071d0a2

Please sign in to comment.