Skip to content
This repository was archived by the owner on Jun 27, 2019. It is now read-only.

Commit e1dce1a

Browse files
committed
Fixing replaceConfigPaths bug. Adding export and replace_config_paths tests
1 parent 7f992db commit e1dce1a

File tree

5 files changed

+81
-38
lines changed

5 files changed

+81
-38
lines changed

bin/generator.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,6 @@ function replaceConfigPaths(config, projectDir, sourceDir, publicDir, exportDir)
9292
const conf = _.assign({}, config);
9393
_.map(conf.paths.source, (value, key) => { conf.paths.source[key] = value.replace(/^\.\/source/g, path.join(projectDir, sourceDir)) });
9494
_.map(conf.paths.public, (value, key) => { conf.paths.public[key] = value.replace(/^\.\/public/g, path.join(projectDir, publicDir)) });
95-
conf.styleguide = 'node_modules/styleguidekit-assets-default/dist/';
96-
conf.patternlabFiles = 'node_modules/styleguidekit-mustache-default/views/';
9795
conf.patternExportDirectory = path.join(projectDir, exportDir);
9896
return conf;
9997
}

test/build.test.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,13 @@ const patternLabMock = require('./mocks/patternlab.mock');
66
// Require build and mock patternlab.build() so that we only test the build module behavior
77
const build = proxyquire('../bin/build', {'patternlab-node': patternLabMock});
88
const opts = {patternsOnly: true};
9-
tap.throws(() => { build() }, {}, 'build throws when config is empty');
10-
tap.throws(() => { build(123) }, {}, 'build throws when config is not of type object');
11-
tap.throws(() => { build(undefined, opts) }, {}, 'build --patterns-only throws when config is empty');
12-
tap.throws(() => { build(undefined, opts) }, {}, 'build --patterns-only throws when config is not of type object');
13-
tap.type(build(config), 'boolean', 'build returns a bool');
14-
tap.type(build(config, opts), 'boolean', 'build --patterns-only returns a bool');
9+
10+
tap.test('Build ->', t => {
11+
t.throws(() => { build() }, {}, 'throws when config is empty');
12+
t.throws(() => { build(123) }, {}, 'throws when config is not of type object');
13+
t.throws(() => { build(undefined, opts) }, {}, '--patterns-only throws when config is empty');
14+
t.throws(() => { build(undefined, opts) }, {}, '--patterns-only throws when config is not of type object');
15+
t.type(build(config), 'boolean', 'returns a bool');
16+
t.type(build(config, opts), 'boolean', '--patterns-only returns a bool');
17+
t.end();
18+
});

test/export.test.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
const proxyquire = require('proxyquire');
2+
const tap = require('tap');
3+
const config = require('../bin/generator').defaultPatternlabConfig;
4+
const patternLabMock = require('./mocks/patternlab.mock');
5+
6+
// Require build and mock patternlab.build() so that we only test the build module behavior
7+
const exportPatterns = proxyquire('../bin/export', {'patternlab-node': patternLabMock});
8+
const opts = {patternsOnly: true};
9+
10+
tap.test('Export ->', t => {
11+
t.throws(() => { exportPatterns() }, {}, 'throws when config is empty');
12+
t.throws(() => { exportPatterns(123) }, {}, 'throws when config is not of type object');
13+
t.throws(() => { exportPatterns(undefined, opts) }, {}, '--patterns-only throws when config is empty');
14+
t.throws(() => { exportPatterns(undefined, opts) }, {}, '--patterns-only throws when config is not of type object');
15+
t.end();
16+
});

test/fixtures/patternlab-config.json

Lines changed: 40 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,45 @@
11
{
2-
"paths" : {
3-
"source" : {
2+
"paths": {
3+
"source": {
44
"root": "./source/",
5-
"patterns" : "./source/_patterns/",
6-
"data" : "./source/_data/",
5+
"patterns": "./source/_patterns/",
6+
"data": "./source/_data/",
77
"meta": "./source/_meta/",
8-
"annotations" : "./source/_annotations/",
9-
"styleguide" : "node_modules/styleguidekit-assets-default/dist/",
10-
"patternlabFiles" : "node_modules/styleguidekit-mustache-default/views/",
11-
"js" : "./source/js",
12-
"images" : "./source/images",
13-
"fonts" : "./source/fonts",
14-
"css" : "./source/css/"
8+
"annotations": "./source/_annotations/",
9+
"styleguide": "node_modules/styleguidekit-assets-default/dist/",
10+
"patternlabFiles": "node_modules/styleguidekit-mustache-default/views/",
11+
"js": "./source/js",
12+
"images": "./source/images",
13+
"fonts": "./source/fonts",
14+
"css": "./source/css/"
1515
},
16-
"public" : {
17-
"root" : "./public/",
18-
"patterns" : "./public/patterns/",
19-
"data" : "./public/styleguide/data/",
20-
"annotations" : "./public/annotations/",
21-
"styleguide" : "./public/styleguide/",
22-
"js" : "./public/js",
23-
"images" : "./public/images",
24-
"fonts" : "./public/fonts",
25-
"css" : "./public/css"
16+
"public": {
17+
"root": "./public/",
18+
"patterns": "./public/patterns/",
19+
"data": "./public/styleguide/data/",
20+
"annotations": "./public/annotations/",
21+
"styleguide": "./public/styleguide/",
22+
"js": "./public/js",
23+
"images": "./public/images",
24+
"fonts": "./public/fonts",
25+
"css": "./public/css"
2626
}
2727
},
2828
"styleGuideExcludes": [
2929
"templates",
3030
"pages"
3131
],
3232
"defaultPattern": "all",
33-
"cleanPublic" : false,
33+
"cleanPublic": false,
3434
"patternExtension": "mustache",
35-
"ignored-extensions" : ["scss", "DS_Store", "less"],
36-
"ignored-directories" : ["scss"],
35+
"ignored-extensions": [
36+
"scss",
37+
"DS_Store",
38+
"less"
39+
],
40+
"ignored-directories": [
41+
"scss"
42+
],
3743
"debug": false,
3844
"ishControlsHide": {
3945
"s": false,
@@ -54,15 +60,19 @@
5460
},
5561
"ishMinimum": "240",
5662
"ishMaximum": "2600",
57-
"patternStateCascade": ["inprogress", "inreview", "complete"],
63+
"patternStateCascade": [
64+
"inprogress",
65+
"inreview",
66+
"complete"
67+
],
5868
"patternStates": {
59-
"molecules-single-comment" : "complete",
60-
"organisms-sticky-comment" : "inreview",
61-
"templates-article" : "complete"
69+
"molecules-single-comment": "complete",
70+
"organisms-sticky-comment": "inreview",
71+
"templates-article": "complete"
6272
},
6373
"patternExportPatternPartials": [],
64-
"patternExportDirectory": "./pattern_exports/",
65-
"baseurl" : "",
74+
"patternExportDirectory": "./pattern_exports",
75+
"baseurl": "",
6676
"cacheBust": true,
6777
"starterkitSubDir": "dist",
6878
"outputFileSuffixes": {

test/replace_config_paths.test.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
const tap = require('tap');
2+
const replaceConfigPaths = require('../bin/generator').replaceConfigPaths;
3+
const config = require('./fixtures/patternlab-config.json');
4+
5+
tap.test('replaceConfigPaths ->', t => {
6+
const newConfig = replaceConfigPaths(config, 'projectDir', 'sourceDir', 'publicDir', 'exportDir');
7+
for (const k of Object.keys(newConfig.paths.source)) {
8+
t.ok(/^projectDir\/sourceDir\/|^node_modules/.test(newConfig.paths.source[k]), `should be ok for newConfig.paths.source.${k}`);
9+
}
10+
for (const k of Object.keys(newConfig.paths.public)) {
11+
t.ok(/^projectDir\/publicDir\//.test(newConfig.paths.public[k]), `should be ok for newConfig.paths.public.${k}`);
12+
}
13+
t.ok(/^projectDir\/exportDir\//.test(newConfig.paths.patternExportDirectory), `should be ok for newConfig.paths.patternExportDirectory`);
14+
t.end();
15+
});

0 commit comments

Comments
 (0)