Skip to content

Commit

Permalink
Fix tests on Windows. (#330)
Browse files Browse the repository at this point in the history
/CC @addyosmani @bezoerb 

Locally on Windows I get `103 passing (1m)`
  • Loading branch information
XhmikosR authored and bezoerb committed Oct 20, 2018
1 parent 4b038e0 commit 9922aab
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions test/03-cli.js
Expand Up @@ -15,6 +15,8 @@ const serveStatic = require('serve-static');
process.chdir(path.resolve(__dirname));
process.setMaxListeners(0);

const CAT = process.platform === 'win32' ? 'type' : 'cat';

describe('CLI', () => {
beforeEach(function (done) {
readJson('../package.json', (err, data) => {
Expand Down Expand Up @@ -59,15 +61,7 @@ describe('CLI', () => {
});

it('should work well with the critical CSS file piped to critical', function (done) {
let cmd;

if (process.platform === 'win32') {
cmd = 'type';
} else {
cmd = 'cat';
}

cmd += ' ' + path.normalize('fixtures/generate-default.html') + ' | node ' + path.join(__dirname, '../', this.pkg.bin.critical) + ' --base fixtures --width 1300 --height 900';
const cmd = `${CAT} ${path.normalize('fixtures/generate-default.html')} | node ${path.join(__dirname, '../', this.pkg.bin.critical)} --base fixtures --width 1300 --height 900`;

const cp = exec(cmd);

Expand All @@ -82,7 +76,7 @@ describe('CLI', () => {
});

it('should work well with the html file inside a folder piped to critical', function (done) {
const cmd = 'cat fixtures/folder/generate-default.html | node ' + path.join(__dirname, '../', this.pkg.bin.critical) + ' --base fixtures --width 1300 --height 900';
const cmd = `${CAT} ${path.normalize('fixtures/folder/generate-default.html')} | node ${path.join(__dirname, '../', this.pkg.bin.critical)} --base fixtures --width 1300 --height 900`;
const expected = fs.readFileSync(path.join(__dirname, 'expected/generate-default.css'), 'utf8');

exec(cmd, (error, stdout) => {
Expand All @@ -93,7 +87,7 @@ describe('CLI', () => {
});

it('should inline the images with the html file inside a folder piped to critical', function (done) {
const cmd = 'cat fixtures/generate-image.html | node ' + path.join(__dirname, '../', this.pkg.bin.critical) + ' -c fixtures/styles/image-relative.css --inlineImages --base fixtures --width 1300 --height 900';
const cmd = `${CAT} ${path.normalize('fixtures/generate-image.html')} | node ${path.join(__dirname, '../', this.pkg.bin.critical)} -c fixtures/styles/image-relative.css --inlineImages --base fixtures --width 1300 --height 900`;
const expected = fs.readFileSync(path.join(__dirname, 'expected/generate-image.css'), 'utf8');

exec(cmd, (error, stdout) => {
Expand All @@ -104,7 +98,7 @@ describe('CLI', () => {
});

it('should add the correct image path to critical css', function (done) {
const cmd = 'cat fixtures/folder/generate-image.html | node ' + path.join(__dirname, '../', this.pkg.bin.critical) + ' -c fixtures/styles/image-relative.css --base fixtures --width 1300 --height 900';
const cmd = `${CAT} ${path.normalize('fixtures/folder/generate-image.html')} | node ${path.join(__dirname, '../', this.pkg.bin.critical)} -c fixtures/styles/image-relative.css --base fixtures --width 1300 --height 900`;
const expected = fs.readFileSync(path.join(__dirname, 'expected/generate-image-relative.css'), 'utf8');

exec(cmd, (error, stdout) => {
Expand All @@ -115,7 +109,7 @@ describe('CLI', () => {
});

it('should show warning on piped file without relative links and use "/"', function (done) {
const cmd = 'cat fixtures/folder/subfolder/generate-image-absolute.html | node ' + path.join(__dirname, '../', this.pkg.bin.critical) + ' --base fixtures --width 1300 --height 900';
const cmd = `${CAT} ${path.normalize('fixtures/folder/subfolder/generate-image-absolute.html')} | node ${path.join(__dirname, '../', this.pkg.bin.critical)} --base fixtures --width 1300 --height 900`;
const expected = fs.readFileSync(path.join(__dirname, 'expected/generate-image-absolute.css'), 'utf8');

exec(cmd, (error, stdout, stderr) => {
Expand Down

0 comments on commit 9922aab

Please sign in to comment.