Skip to content

Commit

Permalink
fix ci/cd on master branch (#1267)
Browse files Browse the repository at this point in the history
  • Loading branch information
fivethreeo authored Apr 25, 2020
1 parent 91a7d67 commit ecd1ee4
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 27 deletions.
32 changes: 26 additions & 6 deletions test/fixtures/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,45 @@
const shell = require('shelljs');
const path = require('path');
const rootDir = process.cwd();
const fs = require('fs-extra');


// shell.config.silent = true;

module.exports = {
setupStageWithFixture: (stageName, fixtureName) => {
const stagePath = path.join(rootDir, stageName);
shell.mkdir(stagePath);
shell.exec(`cp -a ${rootDir}/test/fixtures/${fixtureName}/. ${stagePath}/`);
shell.ln(
'-s',
path.join(rootDir, 'packages/razzle/node_modules'),

fs.copySync(path.join(rootDir, 'test', 'fixtures', fixtureName), stagePath);
fs.ensureSymlinkSync(
path.join(rootDir, 'node_modules'),
path.join(stagePath, 'node_modules')
);
fs.ensureSymlinkSync(
path.join(rootDir, 'packages'),
path.join(stagePath, 'packages')
);
shell.cd(stagePath);
},

setupStageWithExample: (stageName, exampleName) => {
const stagePath = path.join(rootDir, stageName);

fs.copySync(path.join(rootDir, 'examples', exampleName), stagePath);
fs.ensureSymlinkSync(
path.join(rootDir, 'node_modules'),
path.join(stagePath, 'node_modules')
);
fs.ensureSymlinkSync(
path.join(rootDir, 'packages'),
path.join(stagePath, 'packages')
);
shell.cd(stagePath);
},

teardownStage: stageName => {
shell.cd(rootDir);
shell.rm('-rf', path.join(rootDir, stageName));
fs.removeSync(path.join(rootDir, stageName));
},

rootDir,
Expand Down
4 changes: 2 additions & 2 deletions test/jest.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"roots": ["<rootDir>/tests"],
"collectCoverageFrom": ["**/*.js"],
"testMatch": [
"<rootDir>/tests/**/*(*.)@(spec|test).(ts|js)?(x)"
"<rootDir>/tests/**/*(*.)@(spec|test).(ts|js)?(x)"
]
}
}
19 changes: 11 additions & 8 deletions test/tests/razzle-start-spa.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,29 @@ const fs = require('fs');

shell.config.silent = true;

const stageName = 'stage-start-spa';

describe('razzle start', () => {
describe('razzle basic example', () => {

beforeAll(() => {
shell.cd(path.join(util.rootDir, 'examples/basic-spa'));
util.teardownStage(stageName);
});

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

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(
'./node_modules/.bin/razzle start --type=spa',
`${path.join('./node_modules/.bin/razzle')} start --type=spa`,
() => {
resolve(outputTest);
}
);
child.stdout.on('data', data => {
console.log(data);
if (data.includes('> SPA Started on port 3000')) {
shell.exec('sleep 5');
const devServerOutput = shell.exec(
Expand All @@ -45,16 +50,18 @@ describe('razzle start', () => {
jasmine.DEFAULT_TIMEOUT_INTERVAL = 400000; // eslint-disable-line no-undef

it('should build and run in spa mode', () => {
util.setupStageWithExample(stageName, 'basic-spa');
let outputTest;
shell.exec('./node_modules/.bin/razzle build --type=spa');
shell.exec(`${path.join('./node_modules/.bin/razzle')} build --type=spa`);
const run = new Promise(resolve => {
const child = shell.exec(
'./node_modules/.bin/serve -s build/public',
`${path.join('./node_modules/.bin/serve')} -s ${path.join('build/public')}`,
() => {
resolve(outputTest);
}
);
child.stdout.on('data', data => {
console.log(data);
if (data.includes('http://localhost:5000')) {
shell.exec('sleep 5');
// we use serve package and it will run in prot 5000
Expand All @@ -67,9 +74,5 @@ describe('razzle start', () => {
return run.then(test => expect(test).toBeTruthy());
});

afterAll(() => {
shell.rm('-rf', 'build');
shell.cd(util.rootDir);
});
});
});
23 changes: 12 additions & 11 deletions test/tests/razzle-start.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,21 @@ const path = require('path');

shell.config.silent = true;

const stageName = 'stage-start';

describe('razzle start', () => {
describe('razzle basic example', () => {
beforeAll(() => {
shell.cd(path.join(util.rootDir, 'examples/basic'));
util.teardownStage(stageName);
});

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

it('should start a dev server', () => {
util.setupStageWithExample(stageName, 'basic');
let outputTest;
const run = new Promise(resolve => {
const child = shell.exec('./node_modules/.bin/razzle start', () => {
const child = shell.exec(`${path.join('./node_modules/.bin/razzle')} start`, () => {
resolve(outputTest);
});
child.stdout.on('data', data => {
Expand All @@ -41,12 +44,10 @@ describe('razzle start', () => {
jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000000; // eslint-disable-line no-undef

it('should start a dev server on different port', () => {
shell.cd(
path.join(util.rootDir, 'examples/with-custom-devserver-options')
);
util.setupStageWithExample(stageName, 'with-custom-devserver-options');
let outputTest;
const run = new Promise(resolve => {
const child = shell.exec('./node_modules/.bin/razzle start', () => {
const child = shell.exec(`${path.join('./node_modules/.bin/razzle')} start`, () => {
resolve(outputTest);
});
child.stdout.on('data', data => {
Expand All @@ -68,10 +69,11 @@ describe('razzle start', () => {
jasmine.DEFAULT_TIMEOUT_INTERVAL = 400000; // eslint-disable-line no-undef

it('should build and run', () => {
util.setupStageWithExample(stageName, 'basic');
let outputTest;
shell.exec('./node_modules/.bin/razzle build');
shell.exec(`${path.join('./node_modules/.bin/razzle')} build`);
const run = new Promise(resolve => {
const child = shell.exec('node build/server.js', () => {
const child = shell.exec(`node ${path.join('build/server.js')}`, () => {
resolve(outputTest);
});
child.stdout.on('data', data => {
Expand All @@ -86,9 +88,8 @@ describe('razzle start', () => {
return run.then(test => expect(test).toBeTruthy());
});

afterAll(() => {
shell.rm('-rf', 'build');
shell.cd(util.rootDir);
afterEach(() => {
util.teardownStage(stageName);
});
});
});

0 comments on commit ecd1ee4

Please sign in to comment.