Skip to content

Commit

Permalink
fix(test): next branch (#1271)
Browse files Browse the repository at this point in the history
  • Loading branch information
fivethreeo authored Apr 26, 2020
1 parent 604b510 commit 0cfc989
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 67 deletions.
12 changes: 0 additions & 12 deletions test/fixtures/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,6 @@ module.exports = {
shell.cd(stagePath);
},

setupStageWithExample: (stageName, exampleName) => {
const stagePath = path.join(rootDir, stageName);
shell.mkdir(stagePath);
shell.exec(`cp -a ${rootDir}/examples/${exampleName}/. ${stagePath}/`);
shell.ln(
'-s',
path.join(rootDir, 'packages/razzle/node_modules'),
path.join(stagePath, 'node_modules')
);
shell.cd(stagePath);
},

teardownStage: stageName => {
shell.cd(rootDir);
fs.removeSync(path.join(rootDir, stageName));
Expand Down
2 changes: 1 addition & 1 deletion test/tests/razzle-build.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ describe('razzle build', () => {

expect(output.code).toBe(0);
});

it('should exit with an error code when the custom config is invalid', () => {
util.setupStageWithFixture(stageName, 'build-with-custom-config-invalid');
const output = shell.exec('yarn build', {
Expand Down
38 changes: 21 additions & 17 deletions test/tests/razzle-start-spa.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,16 @@ describe("razzle start", () => {
it("should start a dev server for spa mode", () => {
util.setupStageWithExample(stageName, "basic-spa");
let outputTest;
const run = new Promise((resolve) => {
const child = shell.exec("razzle start --type=spa --verbose", () => {
resolve(outputTest);
});
child.stdout.on("data", (data) => {
console.log(data);
if (data.includes("> SPA Started on port 3000")) {
shell.exec("sleep 5");
const run = new Promise(resolve => {
const child = shell.exec(
`${path.join('./node_modules/.bin/razzle')} start --type=spa --verbose`,
() => {
resolve(outputTest);
}
);
child.stdout.on('data', data => {
if (data.includes('> SPA Started on port 3000')) {
shell.exec('sleep 5');
const devServerOutput = shell.exec(
'curl -sb -o "" localhost:3000/static/js/bundle.js'
);
Expand All @@ -47,15 +49,17 @@ describe("razzle start", () => {
it("should build and run in spa mode", () => {
util.setupStageWithExample(stageName, "basic-spa");
let outputTest;
shell.exec("razzle build --type=spa");
const run = new Promise((resolve) => {
const child = shell.exec("serve -s build/public", () => {
resolve(outputTest);
});
child.stdout.on("data", (data) => {
console.log(data);
if (data.includes("http://localhost:5000")) {
shell.exec("sleep 5");
shell.exec(`${path.join('./node_modules/.bin/razzle')} build --type=spa`);
const run = new Promise(resolve => {
const child = shell.exec(
`${path.join('./node_modules/.bin/serve')} -s ${path.join('build/public')}`,
() => {
resolve(outputTest);
}
);
child.stdout.on('data', data => {
if (data.includes('http://localhost:5000')) {
shell.exec('sleep 5');
// we use serve package and it will run in prot 5000
const output = shell.exec("curl -I localhost:5000");
outputTest = output.stdout.includes("200");
Expand Down
74 changes: 37 additions & 37 deletions test/tests/razzle-start.test.js
Original file line number Diff line number Diff line change
@@ -1,91 +1,91 @@
/**
* @jest-environment node
*/
"use strict";
'use strict';

const shell = require("shelljs");
const util = require("../fixtures/util");
const kill = require("../utils/psKill");
const path = require("path");
const shell = require('shelljs');
const util = require('../fixtures/util');
const kill = require('../utils/psKill');
const path = require('path');

shell.config.silent = true;

const stageName = "stage-start";
const stageName = 'stage-start';

describe("razzle start", () => {
describe("razzle basic example", () => {
describe('razzle start', () => {
describe('razzle basic example', () => {
beforeAll(() => {
util.teardownStage(stageName);
});

jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000000; // eslint-disable-line no-undef

it("should start a dev server", () => {
util.setupStageWithExample(stageName, "basic");
it('should start a dev server', () => {
util.setupStageWithExample(stageName, 'basic');
let outputTest;
const run = new Promise((resolve) => {
const child = shell.exec("razzle start --verbose", () => {
const run = new Promise(resolve => {
const child = shell.exec(`${path.join('./node_modules/.bin/razzle')} start --verbose`, () => {
resolve(outputTest);
});
child.stdout.on("data", (data) => {
if (data.includes("Server-side HMR Enabled!")) {
shell.exec("sleep 5");
child.stdout.on('data', data => {
if (data.includes('Server-side HMR Enabled!')) {
shell.exec('sleep 5');
const devServerOutput = shell.exec(
'curl -sb -o "" localhost:3001/static/js/bundle.js'
);
outputTest = devServerOutput.stdout.includes("React");
outputTest = devServerOutput.stdout.includes('React');
kill(child.pid);
}
});
});
return run.then((test) => expect(test).toBeTruthy());
return run.then(test => expect(test).toBeTruthy());
});

jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000000; // eslint-disable-line no-undef

it("should start a dev server on different port", () => {
util.setupStageWithExample(stageName, "with-custom-devserver-options");
it('should start a dev server on different port', () => {
util.setupStageWithExample(stageName, 'with-custom-devserver-options');
let outputTest;
const run = new Promise((resolve) => {
const child = shell.exec("razzle start --verbose", () => {
const run = new Promise(resolve => {
const child = shell.exec(`${path.join('./node_modules/.bin/razzle')} start --verbose`, () => {
resolve(outputTest);
});
child.stdout.on("data", (data) => {
if (data.includes("Server-side HMR Enabled!")) {
shell.exec("sleep 5");
child.stdout.on('data', data => {
if (data.includes('Server-side HMR Enabled!')) {
shell.exec('sleep 5');
const devServerOutput = shell.exec(
'curl -sb -o "" localhost:3002/static/js/bundle.js'
);
outputTest = devServerOutput.stdout.includes(
"index.js?http://localhost:3002"
'index.js?http://localhost:3002'
);
kill(child.pid);
}
});
});
return run.then((test) => expect(test).toBeTruthy());
return run.then(test => expect(test).toBeTruthy());
});

jasmine.DEFAULT_TIMEOUT_INTERVAL = 400000; // eslint-disable-line no-undef

it("should build and run", () => {
util.setupStageWithExample(stageName, "basic");
it('should build and run', () => {
util.setupStageWithExample(stageName, 'basic');
let outputTest;
shell.exec("razzle build");
const run = new Promise((resolve) => {
const child = shell.exec(`node ${path.join("build/server.js")}`, () => {
shell.exec(`${path.join('./node_modules/.bin/razzle')} build`);
const run = new Promise(resolve => {
const child = shell.exec(`node ${path.join('build/server.js')}`, () => {
resolve(outputTest);
});
child.stdout.on("data", (data) => {
if (data.includes("> Started on port 3000")) {
shell.exec("sleep 5");
const output = shell.exec("curl -I localhost:3000");
outputTest = output.stdout.includes("200");
child.stdout.on('data', data => {
if (data.includes('> Started on port 3000')) {
shell.exec('sleep 5');
const output = shell.exec('curl -I localhost:3000');
outputTest = output.stdout.includes('200');
kill(child.pid);
}
});
});
return run.then((test) => expect(test).toBeTruthy());
return run.then(test => expect(test).toBeTruthy());
});

afterEach(() => {
Expand Down

0 comments on commit 0cfc989

Please sign in to comment.