Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix --compiler flag #438

Merged
merged 5 commits into from
Sep 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ install:
- npm install

test_script:
- npm run test-only
- appveyor-retry npm run test-only

build: off
6 changes: 2 additions & 4 deletions lib/elm-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,13 @@ if (args.compiler === undefined) {
}
} else {
try {
pathToElmBinary = which.sync(path.resolve(args.compiler));
pathToElmBinary = path.resolve(which.sync(args.compiler));

elmVersion = spawn
.sync(pathToElmBinary, ['--version'], { encoding: 'utf-8' })
.stdout.trim();
} catch (error) {
throw new Error(
'The --compiler option must be given a path to an elm executable.'
);
throw new Error('The elm executable passed to --compiler must exist.');
}
}

Expand Down
1 change: 1 addition & 0 deletions tests/fixtures/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/elm-stuff/
/scratch/
/dummy-bin/different-elm*
35 changes: 32 additions & 3 deletions tests/flags.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const xml2js = require('xml2js');
const readline = require('readline');
const stripAnsi = require('strip-ansi');

const { fixturesDir, spawnOpts } = require('./util');
const { fixturesDir, spawnOpts, dummyBinPath } = require('./util');

const elmTestPath = path.join(__dirname, '..', 'bin', 'elm-test');

Expand Down Expand Up @@ -265,7 +265,16 @@ describe('flags', () => {
}).timeout(60000);
});

describe('--compiler', () => {
describe.only('--compiler', () => {
before(() => {
// Warning: this assumes the directory structure of the elm npm module.
// It may break with new npm versions of elm.
const ext = process.platform === 'win32' ? '.exe' : '';
const elmExe = require.resolve('elm/bin/elm' + ext);
shell.mkdir('-p', dummyBinPath);
shell.cp(elmExe, path.join(dummyBinPath, 'different-elm' + ext));
});

it("Should fail if the given compiler can't be executed", () => {
const runResult = execElmTest([
'elm-test',
Expand All @@ -275,7 +284,27 @@ describe('flags', () => {

assert.ok(Number.isInteger(runResult.status));
assert.notEqual(runResult.status, 0);
}).timeout(5000); // This sometimes needs more time to run on Travis.
}).timeout(5000);

it('Should work with different elm on PATH', () => {
const runResult = execElmTest([
'elm-test',
'--compiler=different-elm',
path.join('tests', 'Passing', 'One.elm'),
]);

assert.equal(runResult.status, 0);
});

it('Should work with local different elm', () => {
const runResult = execElmTest([
'elm-test',
'--compiler=./dummy-bin/different-elm',
path.join('tests', 'Passing', 'One.elm'),
]);

assert.equal(runResult.status, 0);
}).timeout(5000);
});

describe('--watch', () => {
Expand Down
9 changes: 7 additions & 2 deletions tests/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,18 @@ const path = require('path');
const fixturesDir = path.join(__dirname, 'fixtures');

const elmHome = path.join(fixturesDir, 'elm-home');

const dummyBinPath = path.join(fixturesDir, 'dummy-bin');
const newPath = process.env.PATH + path.delimiter + dummyBinPath;
const spawnOpts = {
silent: true,
env: Object.assign({ ELM_HOME: elmHome }, process.env),
env: Object.assign({ ELM_HOME: elmHome }, process.env, {
PATH: newPath,
Path: newPath,
}),
};

module.exports = {
fixturesDir,
spawnOpts,
dummyBinPath,
};