Skip to content

Commit

Permalink
Normalize within tests for OS
Browse files Browse the repository at this point in the history
  • Loading branch information
devinivy committed Dec 2, 2019
1 parent 023d323 commit 778f194
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 23 deletions.
45 changes: 25 additions & 20 deletions test/index.js
Expand Up @@ -30,6 +30,11 @@ const internals = {};

describe('hpal', () => {

const normalize = (str) => {

return str && str.replace(/\\/g, '/').replace(RegExp(Os.EOL, 'g'), '\n');
};

describe('CLI', () => {

const rimraf = (file) => Util.promisify(Rimraf)(`${__dirname}/closet/${file}`, { disableGlob: true });
Expand Down Expand Up @@ -148,7 +153,7 @@ describe('hpal', () => {

expect(result.err).to.be.instanceof(DisplayError);
expect(result.output).to.equal('');
expect(result.errorOutput).to.contain('It\'s ambiguous which directory containing a .hc.js file to use: project-a/.hc.js, project-b/.hc.js');
expect(normalize(result.errorOutput)).to.contain('It\'s ambiguous which directory containing a .hc.js file to use: project-a/.hc.js, project-b/.hc.js');
expect(result.errorOutput.match(/,/g)).to.have.length(1);
});

Expand All @@ -158,7 +163,7 @@ describe('hpal', () => {

expect(result1.err).to.be.instanceof(DisplayError);
expect(result1.output).to.equal('');
expect(result1.errorOutput).to.contain('It\'s ambiguous which directory containing a .hc.js file to use: ../project-a/.hc.js, ../project-b/.hc.js');
expect(normalize(result1.errorOutput)).to.contain('It\'s ambiguous which directory containing a .hc.js file to use: ../project-a/.hc.js, ../project-b/.hc.js');
expect(result1.errorOutput.match(/,/g)).to.have.length(1);

const OrigGlob = Glob.Glob;
Expand All @@ -184,7 +189,7 @@ describe('hpal', () => {
expect(Glob.Glob.notOriginal).to.not.exist();
expect(result2.err).to.be.instanceof(DisplayError);
expect(result2.output).to.equal('');
expect(result2.errorOutput).to.contain('It\'s ambiguous which directory containing a .hc.js file to use: ../project-b/.hc.js, ../project-a/.hc.js');
expect(normalize(result2.errorOutput)).to.contain('It\'s ambiguous which directory containing a .hc.js file to use: ../project-b/.hc.js, ../project-a/.hc.js');
expect(result2.errorOutput.match(/,/g)).to.have.length(1);
});

Expand All @@ -197,7 +202,7 @@ describe('hpal', () => {
const result = await RunUtil.cli(['make', 'route'], 'ambiguous-hc-file/project-a');

expect(result.err).to.not.exist();
expect(result.output).to.contain('Wrote routes/index.js');
expect(normalize(result.output)).to.contain('Wrote routes/index.js');
expect(result.errorOutput).to.equal('');

const contents = await read('ambiguous-hc-file/project-a/routes/index.js');
Expand All @@ -214,7 +219,7 @@ describe('hpal', () => {
const result = await RunUtil.cli(['make', 'route'], 'non-ambiguous-hc-file-cwd/project-a');

expect(result.err).to.not.exist();
expect(result.output).to.contain('Wrote ../project-b/routes/index.js');
expect(normalize(result.output)).to.contain('Wrote ../project-b/routes/index.js');
expect(result.errorOutput).to.equal('');

const contents = await read('non-ambiguous-hc-file-cwd/project-b/routes/index.js');
Expand All @@ -238,7 +243,7 @@ describe('hpal', () => {
expect(result.err).to.be.instanceof(DisplayError);
expect(result.output).to.equal('');
expect(result.errorOutput).to.contain('The file');
expect(result.errorOutput).to.contain('file-already-exists/routes/some-route.js');
expect(normalize(result.errorOutput)).to.contain('file-already-exists/routes/some-route.js');
expect(result.errorOutput).to.contain('already exists.');
});

Expand Down Expand Up @@ -318,7 +323,7 @@ describe('hpal', () => {

const result = await promise;
expect(result.err).to.not.exist();
expect(result.output).to.contain('Wrote lib/routes/index.js');
expect(normalize(result.output)).to.contain('Wrote lib/routes/index.js');
expect(result.errorOutput).to.equal('');

const contents = await read('list-as-dir/lib/routes/index.js');
Expand All @@ -342,7 +347,7 @@ describe('hpal', () => {

const result = await promise;
expect(result.err).to.not.exist();
expect(result.output).to.contain('Wrote lib/routes.js');
expect(normalize(result.output)).to.contain('Wrote lib/routes.js');
expect(result.errorOutput).to.equal('');

const contents = await read('list-as-file/lib/routes.js');
Expand All @@ -365,7 +370,7 @@ describe('hpal', () => {

const result = await promise;
expect(result.err).to.not.exist();
expect(result.output).to.contain('Wrote lib/bind/index.js');
expect(normalize(result.output)).to.contain('Wrote lib/bind/index.js');
expect(result.errorOutput).to.equal('');

const contents = await read('single-as-dir/lib/bind/index.js');
Expand All @@ -388,7 +393,7 @@ describe('hpal', () => {

const result = await promise;
expect(result.err).to.not.exist();
expect(result.output).to.contain('Wrote lib/bind.js');
expect(normalize(result.output)).to.contain('Wrote lib/bind.js');
expect(result.errorOutput).to.equal('');

const contents = await read('single-as-file/lib/bind.js');
Expand Down Expand Up @@ -431,7 +436,7 @@ describe('hpal', () => {

const result = await promise;
expect(result.err).to.not.exist();
expect(result.output).to.contain('Wrote lib/bind.js');
expect(normalize(result.output)).to.contain('Wrote lib/bind.js');
expect(result.errorOutput).to.equal('');

const contents = await read('single-as-file/lib/bind.js');
Expand All @@ -451,7 +456,7 @@ describe('hpal', () => {

const result = await promise;
expect(result.err).to.not.exist();
expect(result.output).to.contain('Wrote lib/x.js');
expect(normalize(result.output)).to.contain('Wrote lib/x.js');
expect(result.errorOutput).to.equal('');

const contents = await read('no-example-or-signature/lib/x.js');
Expand All @@ -478,7 +483,7 @@ describe('hpal', () => {

const result = await promise;
expect(result.err).to.not.exist();
expect(result.output).to.contain('Wrote lib/x.js');
expect(normalize(result.output)).to.contain('Wrote lib/x.js');
expect(result.errorOutput).to.equal('');

const contents = await read('no-example-with-signature/lib/x.js');
Expand Down Expand Up @@ -509,7 +514,7 @@ describe('hpal', () => {

const result = await promise;
expect(result.err).to.not.exist();
expect(result.output).to.contain('Wrote lib/x.js');
expect(normalize(result.output)).to.contain('Wrote lib/x.js');
expect(result.errorOutput).to.equal('');

const contents = await read('with-example-and-signature/lib/x.js');
Expand Down Expand Up @@ -540,7 +545,7 @@ describe('hpal', () => {

const result = await promise;
expect(result.err).to.not.exist();
expect(result.output).to.contain('Wrote lib/x.js');
expect(normalize(result.output)).to.contain('Wrote lib/x.js');
expect(result.errorOutput).to.equal('');

const contents = await read('with-example-and-requires/lib/x.js');
Expand Down Expand Up @@ -571,7 +576,7 @@ describe('hpal', () => {

const result = await promise;
expect(result.err).to.not.exist();
expect(result.output).to.contain('Wrote lib/x/index.js');
expect(normalize(result.output)).to.contain('Wrote lib/x/index.js');
expect(result.errorOutput).to.equal('');

const contents = await read('listed-example/lib/x/index.js');
Expand All @@ -591,7 +596,7 @@ describe('hpal', () => {

const result = await promise;
expect(result.err).to.not.exist();
expect(result.output).to.contain('Wrote lib/x/y.js');
expect(normalize(result.output)).to.contain('Wrote lib/x/y.js');
expect(result.errorOutput).to.equal('');

const contents = await read('listed-example/lib/x/y.js');
Expand Down Expand Up @@ -619,7 +624,7 @@ describe('hpal', () => {

const result = await promise;
expect(result.err).to.not.exist();
expect(result.output).to.contain('Wrote lib/x.js');
expect(normalize(result.output)).to.contain('Wrote lib/x.js');
expect(result.errorOutput).to.equal('');

const contents = await read('skip-use-strict-header/lib/x.js');
Expand Down Expand Up @@ -1392,7 +1397,7 @@ describe('hpal', () => {

expect(result.err).to.be.instanceof(DisplayError);
expect(result.output).to.equal('');
expect(result.errorOutput).to.contain(`No server found! To run commands the current project must export { deployment: async () => server } from ${root}/server.`);
expect(normalize(result.errorOutput)).to.contain(`No server found! To run commands the current project must export { deployment: async () => server } from ${root}/server.`);
});

it('errors hard when a bad require happens in the server.', async () => {
Expand All @@ -1408,7 +1413,7 @@ describe('hpal', () => {

expect(result.err).to.be.instanceof(DisplayError);
expect(result.output).to.equal('');
expect(result.errorOutput).to.contain(`No server found! To run commands the current project must export { deployment: async () => server } from ${root}/server.`);
expect(normalize(result.errorOutput)).to.contain(`No server found! To run commands the current project must export { deployment: async () => server } from ${root}/server.`);
});

it('errors when calling a vanilla or default command that does not exist.', async () => {
Expand Down
4 changes: 1 addition & 3 deletions test/run-util.js
Expand Up @@ -84,9 +84,7 @@ exports.cli = (argv, cwd, colors) => {
catch (err) {

// Ignore leading and trailing whitespace for testing purposes.
// Also switch \ for /, to handle OS-specific differences in paths.

output = output.replace(/\\/g, '/').trim();
output = output.trim();

if (!(err instanceof DisplayError)) {
err.output = output;
Expand Down

0 comments on commit 778f194

Please sign in to comment.