Skip to content

Commit

Permalink
Support for absolute paths as arguments. Fixes gh-74
Browse files Browse the repository at this point in the history
  • Loading branch information
rwaldron committed Feb 17, 2021
1 parent 6b6c3c5 commit 6628a06
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
6 changes: 5 additions & 1 deletion bin/eshost.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,11 @@ const attrs = {
process.stdin.setEncoding('utf8');

if (fileArg) {
const file = path.join(process.cwd(), fileArg);
const fileArgJoinPath = !path.isAbsolute(fileArg)
? process.cwd()
: '';

const file = path.join(fileArgJoinPath, fileArg);
const contents = fs.readFileSync(file, 'utf8');
const attrs = {
flags: {
Expand Down
42 changes: 42 additions & 0 deletions test/bin/eshost.js
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,48 @@ describe('eshost [input-file]', () => {
});
});

describe('absolute path to script.js', () => {
it('evaluates code and displays the result for all hosts', () => {
return eshost(`${__dirname}/fixtures/script.js`).then(result => {
assert.equal(result.stderr, '');
assert(/#### node/m.test(result.stdout));
assert(/#### engine262/m.test(result.stdout));
});
});

it('evaluates code and displays the result for a specific host', () => {
return eshost(`--host engine262 ${__dirname}/fixtures/script.js`).then(result => {
assert.equal(result.stderr, '');
assert(/#### engine262\ntrue/m.test(result.stdout));
assert(!/#### node\ntrue\n\n/m.test(result.stdout));
});
});

it('evaluates code and displays the result for a specific host group', () => {
return eshost(`--hostGroup engine262 ${__dirname}/fixtures/script.js`).then(result => {
assert.equal(result.stderr, '');
assert(/#### engine262\ntrue/m.test(result.stdout));
assert(!/#### node\ntrue\n\n/m.test(result.stdout));
});
});

it('evaluates code and displays the result for a specific tag', () => {
return eshost(`--tags latest ${__dirname}/fixtures/script.js`).then(result => {
assert.equal(result.stderr, '');
assert(/#### engine262\ntrue/m.test(result.stdout));
assert(!/#### node\ntrue\n\n/m.test(result.stdout));
});
});

it('evaluates code and displays the result for specific tags', () => {
return eshost(`--tags latest,greatest ${__dirname}/fixtures/script.js`).then(result => {
assert.equal(result.stderr, '');
assert(/#### engine262\ntrue/m.test(result.stdout));
assert(!/#### node\ntrue\n\n/m.test(result.stdout));
});
});
});

describe('module.mjs', () => {
it('evaluates code and displays the result for all hosts', () => {
return eshost('test/bin/fixtures/module.mjs').then(result => {
Expand Down

0 comments on commit 6628a06

Please sign in to comment.