Skip to content

Commit

Permalink
Merge pull request #625 from jbenesch/hotfix/generator-rc
Browse files Browse the repository at this point in the history
Ensure generated .reactserverrc option keys match cli option keys
  • Loading branch information
doug-wade authored Aug 26, 2016
2 parents 917880c + 4199e39 commit 0b64f43
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"routes": "./routes.js",
"routesFile": "./routes.js",
"host": "localhost",
"port": 3000,
"js-port": 3001,
"jsPort": 3001,
"hot": false,
"minify": false,
"long-term-caching": false,
"compile-only": false,
"longTermCaching": false,
"compileOnly": false,
"https": false,
"log-level": "debug",
"logLevel": "debug",
"env": {
"staging": {
"port": "4000"
Expand Down
1 change: 1 addition & 0 deletions packages/generator-react-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"devDependencies": {
"ava": "^0.14.0",
"nsp": "^2.3.3",
"react-server-cli": "^0.4.6",
"rimraf": "^2.5.2",
"yeoman-assert": "^2.0.0",
"yeoman-test": "^1.0.0"
Expand Down
41 changes: 41 additions & 0 deletions packages/generator-react-server/test/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import fs from 'fs';
import path from 'path';
import test from 'ava';
import helpers from 'yeoman-test';
import { defaultOptions } from 'react-server-cli';

test('generator-react-server:app creates default files', async t => {
let testDir;
Expand All @@ -24,6 +25,34 @@ test('generator-react-server:app creates default files', async t => {
t.false(await exists('docker-compose.yml', testDir));
});

test('generator-react-server:app .reactserverrc matches react-server-cli default option keys', async t => {
let testDir;
await helpers.run(path.join(__dirname, '../generators/app'))
.inTmpDir(dir => {
testDir = dir;
})
.withPrompts({name: 'foo', dockerCfg: false})
.toPromise();

// Store cli's default option keys in memory
const defaultOptionsKeys = Object.keys(defaultOptions);

// Read .reactserverrc json file generated by the generator
const reactserverrc = await readFile('.reactserverrc', testDir);

// Turn string in to object
const reactserverrcJson = JSON.parse(reactserverrc);

// Make sure .reactserverrc keys are the same as the cli's default options.
Object.keys(reactserverrcJson).forEach(key => {
if (defaultOptionsKeys.indexOf(key) > -1) {
t.pass(`${key} exists in the cli default options`);
} else {
t.fail(`${key} does not exist in the cli default options. Please fix this.`);
}
});
});

test('generator-react-server:app creates docker files', async t => {
let testDir;
await helpers.run(path.join(__dirname, '../generators/app'))
Expand Down Expand Up @@ -65,6 +94,18 @@ function exists(filename, dir) {
});
}

function readFile(filename, dir) {
filename = path.join(dir, filename);
return new Promise((resolve, reject) => {
fs.readFile(filename, 'utf8', (err, data) => {
if (err) {
reject(err);
}
resolve(data);
});
});
}

function runsSuccessfully(command, dir) {
return new Promise((resolve) => {
cp.exec(command, {
Expand Down

0 comments on commit 0b64f43

Please sign in to comment.