Skip to content
This repository was archived by the owner on Oct 16, 2021. It is now read-only.

Commit 2f00fb4

Browse files
committed
feat: first class support for React SPAs
React will be used and set up like described [here](https://github.com/micromata/Baumeister/wiki/Setup-Baumeister-for-React) when choosing to build a single page application.
1 parent 8c329b3 commit 2f00fb4

15 files changed

+334
-412
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ There are tons of options for now :scream:
4545
| `projectName` | Used in the generated README and package.json |
4646
| `projectDescription` | Used in the generated README and package.json |
4747
| `theme` | Name of your Bootstrap theme. Used to name a file and a folder within the Sass directory |
48-
| `projectType` | Adds static site generator abilities (using Handlebars and Frontmatters) if you choose to build a static website |
48+
| `projectType` | Adds static site generator abilities (using Handlebars and Frontmatters), if you choose to build a static website. Sets up React with all the bells and whistles, if you choose to build a single page app. |
4949
| `boilerplateAmount` | Option to choose the amount of boilerplate code (HTML, Sass and JS examples) |
5050
| `license` | Option to define the license type. Defaults to MIT |
5151
| `initialVersion` | Option to define the initial version number used in generated package.json. Defaults to 0.0.0 |

__tests__/test-app.js

Lines changed: 176 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,12 @@ describe('Baumeister with default options', () => {
7373
assert.fileContent(arg);
7474
});
7575

76+
it('should not have historyApiFallback in dev server settings', () => {
77+
assert.noFileContent([
78+
['build/webpack/config.dev-server.js', /historyApiFallback: true,/]
79+
]);
80+
});
81+
7682
it('should have `useHandlebars` set to `true` in baumeister.json', () => {
7783
assert.fileContent('baumeister.json', /"useHandlebars": true,/);
7884
});
@@ -81,6 +87,14 @@ describe('Baumeister with default options', () => {
8187
assert.fileContent('baumeister.json', /"generateBanners": false,/);
8288
});
8389

90+
it('should have the default ProvidePlugin settings in baumeister.json', () => {
91+
assert.fileContent([
92+
['baumeister.json', /"ProvidePlugin": {\n/],
93+
['baumeister.json', /"\$": "jquery",/],
94+
['baumeister.json', /"jQuery": "jquery"/]
95+
]);
96+
});
97+
8498
it('should create package manager files', () => {
8599
assert.file([
86100
'package.json'
@@ -104,6 +118,21 @@ describe('Baumeister with default options', () => {
104118
]);
105119
});
106120

121+
it('should not have React related plugins in .babelrc', () => {
122+
assert.noFileContent([
123+
['src/app/.babelrc', /transform-class-properties/],
124+
['src/app/.babelrc', /transform-react-jsx/]
125+
]);
126+
});
127+
128+
it('should not have React related settings in .eslintrc', () => {
129+
assert.noFileContent([
130+
['.eslintrc.json', /"plugin:react\/recommended"/],
131+
['.eslintrc.json', /"plugins": \["react"],/],
132+
['.eslintrc.json', /"ecmaFeatures": {"jsx": true}/]
133+
]);
134+
});
135+
107136
it('should have `/dist` directory in .gitignore', () => {
108137
assert.fileContent([
109138
['.gitignore', /dist/]
@@ -122,6 +151,14 @@ describe('Baumeister with default options', () => {
122151
]);
123152
});
124153

154+
it('should not create html files', () => {
155+
assert.noFile([
156+
'src/index.html',
157+
'src/stickyFooter.html',
158+
'src/demoElements.html'
159+
]);
160+
});
161+
125162
it('should create other project files', () => {
126163
assert.file([
127164
'README.md',
@@ -135,14 +172,33 @@ describe('Baumeister with default options', () => {
135172
]);
136173
});
137174

175+
it('should create JS file ', () => {
176+
assert.file([
177+
'src/app/base/base.js',
178+
'src/app/index.js',
179+
'src/app/base/polyfills.js'
180+
]);
181+
});
182+
183+
it('should import Bootstrap in index.js', () => {
184+
assert.fileContent([
185+
['src/app/index.js', /import 'bootstrap';/]
186+
]);
187+
});
188+
189+
it('should not use React in index.js', () => {
190+
assert.noFileContent([
191+
['src/app/index.js', /import React from 'react';/],
192+
['src/app/index.js', /import ReactDOM from 'react-dom';/],
193+
['src/app/index.js', /ReactDOM\.render/]
194+
]);
195+
});
196+
138197
it('should create assets', () => {
139198
assert.file([
140199
'src/assets',
141200
'src/assets/fonts',
142201
'src/assets/img',
143-
'src/app/base/base.js',
144-
'src/app/index.js',
145-
'src/app/base/polyfills.js',
146202
'src/assets/scss/index.scss',
147203
'src/assets/scss/_print.scss',
148204
'src/assets/scss/_' + _s.slugify(prompts.theme) + '.scss',
@@ -165,7 +221,7 @@ describe('Baumeister with default options', () => {
165221
]);
166222
});
167223

168-
it('should import `_variables.scss` within `index.scss` file', () => {
224+
it('should import \'_variables.scss\' within \'index.scss\' file', () => {
169225
assert.fileContent([
170226
['src/assets/scss/index.scss', /.\/variables/]
171227
]);
@@ -182,6 +238,31 @@ describe('Baumeister with default options', () => {
182238
packageJson.should.have.property('description', prompts.projectDescription);
183239
});
184240

241+
describe('Dependencies', () => {
242+
it('should have jQuery and popper.js', () => {
243+
assert.fileContent([
244+
['package.json', /jquery/],
245+
['package.json', /popper.js/]
246+
]);
247+
});
248+
249+
it('should not have React and related dependencies', () => {
250+
assert.noFileContent([
251+
['package.json', /react/],
252+
['package.json', /react-dom/],
253+
['package.json', /prop-types/]
254+
]);
255+
});
256+
257+
it('should not have React related dev dependencies', () => {
258+
assert.noFileContent([
259+
['package.json', /eslint-plugin-react/],
260+
['package.json', /babel-plugin-transform-react-jsx/],
261+
['package.json', /babel-plugin-transform-class-properties/]
262+
]);
263+
});
264+
});
265+
185266
it('should render project name and description in README.md', () => {
186267
let regex = new RegExp(escapeStringRegexp(prompts.projectDescription), '');
187268
assert.fileContent('README.md', regex);
@@ -258,7 +339,7 @@ describe('Baumeister with default options', () => {
258339

259340
});
260341

261-
describe('Baumeister with Handlebars disabled', () => {
342+
describe('Baumeister generating a single page app', () => {
262343
// Define prompt answers
263344
const prompts = {
264345
projectName: 'Test this Thingy',
@@ -296,8 +377,11 @@ describe('Baumeister with Handlebars disabled', () => {
296377
.toPromise();
297378
});
298379

299-
it('should have `useHandlebars` set to `false` in baumeister.json', () => {
300-
assert.fileContent('baumeister.json', /"useHandlebars": false,/);
380+
it('should have adapted settings in baumeister.json', () => {
381+
assert.fileContent([
382+
['baumeister.json', /"useHandlebars": false,/],
383+
['baumeister.json', /"ProvidePlugin": {}/]
384+
]);
301385
});
302386

303387
it('should create no Handlebars related files', () => {
@@ -307,13 +391,93 @@ describe('Baumeister with Handlebars disabled', () => {
307391
]);
308392
});
309393

310-
it('should create example html files', () => {
394+
it('should create just the essential html files', () => {
311395
assert.file([
312-
'src/index.html',
396+
'src/index.html'
397+
]);
398+
assert.noFile([
313399
'src/stickyFooter.html',
314400
'src/demoElements.html'
315401
]);
316402
});
403+
404+
it('should have an additional container in index.html', () => {
405+
assert.fileContent([
406+
['src/index.html', /<div id="root" \/>/]
407+
]);
408+
});
409+
410+
it('should have a base element in index.html', () => {
411+
assert.fileContent([
412+
['src/index.html', /<base href="\/">/]
413+
]);
414+
});
415+
416+
it('should not include navigation in index.html', () => {
417+
assert.noFileContent([
418+
['src/index.html', /role="navigation"/]
419+
]);
420+
});
421+
422+
describe('Dependencies', () => {
423+
it('should not have jQuery and popper.js', () => {
424+
assert.noFileContent([
425+
['package.json', /jquery/],
426+
['package.json', /popper.js/]
427+
]);
428+
});
429+
430+
it('should have React and related dependencies', () => {
431+
assert.fileContent([
432+
['package.json', /react/],
433+
['package.json', /react-dom/],
434+
['package.json', /prop-types/]
435+
]);
436+
});
437+
438+
it('should have React related dev dependencies', () => {
439+
assert.fileContent([
440+
['package.json', /eslint-plugin-react/],
441+
['package.json', /babel-plugin-transform-react-jsx/],
442+
['package.json', /babel-plugin-transform-class-properties/]
443+
]);
444+
});
445+
});
446+
447+
it('should have React related plugins in .babelrc', () => {
448+
assert.fileContent([
449+
['src/app/.babelrc', /transform-class-properties/],
450+
['src/app/.babelrc', /transform-react-jsx/]
451+
]);
452+
});
453+
454+
it('should have React related settings in .eslintrc', () => {
455+
assert.fileContent([
456+
['.eslintrc.json', /"plugin:react\/recommended"/],
457+
['.eslintrc.json', /"plugins": \["react"],/],
458+
['.eslintrc.json', /"ecmaFeatures": {"jsx": true}/]
459+
]);
460+
});
461+
462+
it('should have historyApiFallback in dev server settings', () => {
463+
assert.fileContent([
464+
['build/webpack/config.dev-server.js', /historyApiFallback: true,/]
465+
]);
466+
});
467+
468+
it('should not import Bootstrap in index.js', () => {
469+
assert.noFileContent([
470+
['src/app/index.js', /import 'bootstrap';/]
471+
]);
472+
});
473+
474+
it('should use React in index.js', () => {
475+
assert.fileContent([
476+
['src/app/index.js', /import React from 'react';/],
477+
['src/app/index.js', /import ReactDOM from 'react-dom';/],
478+
['src/app/index.js', /ReactDOM\.render/]
479+
]);
480+
});
317481
});
318482

319483
describe('Baumeister with banner', () => {
@@ -554,7 +718,7 @@ describe('Baumeister with GNU General Public License', () => {
554718

555719
});
556720

557-
describe('Baumeister with less boilerplate code and handlebars enabled', () => {
721+
describe('Baumeister with less boilerplate code as static website', () => {
558722

559723
// Define prompt answers
560724
const prompts = {
@@ -633,7 +797,7 @@ describe('Baumeister with less boilerplate code and handlebars enabled', () => {
633797
});
634798
});
635799

636-
describe('Baumeister with less boilerplate code and handlebars disabled', () => {
800+
describe('Baumeister with less boilerplate code as single page app', () => {
637801

638802
// Define prompt answers
639803
const prompts = {
@@ -854,7 +1018,7 @@ describe('Baumeister using --yo-rc flag', () => {
8541018
]);
8551019
});
8561020

857-
it('should import `_variables.scss` within `index.scss` file', () => {
1021+
it('should import \'_variables.scss\' within \'index.scss\' file', () => {
8581022
assert.fileContent([
8591023
['src/assets/scss/index.scss', /.\/variables/]
8601024
]);

0 commit comments

Comments
 (0)