Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -373,16 +373,16 @@ const patternlab_module = function(config) {

this.events.on('patternlab-pattern-change', () => {
if (!patternlab.isBusy) {
options.cleanPublic = false;
return this.build(options);
}
return Promise.resolve();
});

this.events.on('patternlab-global-change', () => {
if (!patternlab.isBusy) {
options.cleanPublic = true; //rebuild everything
return this.build(options);
return this.build(
Object.assign({}, options, { cleanPublic: true }) // rebuild everything
);
}
return Promise.resolve();
});
Expand Down
6 changes: 4 additions & 2 deletions core/lib/changes_hunter.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
'use strict';
const fs = require('fs-extra');
const CompileState = require('./object_factory').CompileState;

//this is mocked in unit tests
let fs = require('fs-extra'); //eslint-disable-line prefer-const

/**
* For detecting changed patterns.
* @constructor
Expand Down Expand Up @@ -73,7 +75,7 @@ ChangesHunter.prototype = {
* @param {string} file
*/
checkLastModified: function(currentPattern, file) {
if (file) {
if (file && fs.pathExistsSync(file)) {
try {
const stat = fs.statSync(file);

Expand Down
10 changes: 9 additions & 1 deletion core/lib/loadPattern.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,15 @@ module.exports = function(relPath, patternlab) {
//find any pattern parameters that may be in the current pattern
currentPattern.parameteredPartials = currentPattern.findPartialsWithPatternParameters();

[templatePath, jsonFilename, listJsonFileName].forEach(file => {
[
templatePath,
`${jsonFilename}.json`,
`${jsonFilename}.yml`,
`${jsonFilename}.yaml`,
`${listJsonFileName}.json`,
`${listJsonFileName}.yml`,
`${listJsonFileName}.yaml`,
].forEach(file => {
changes_hunter.checkLastModified(currentPattern, file);
});

Expand Down
68 changes: 68 additions & 0 deletions test/changes_hunter_tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
'use strict';

const tap = require('tap');
const rewire = require('rewire');

const ch = rewire('../core/lib/changes_hunter');

const fsMock = {
statSync: function() {
return {
mtime: {
getTime: () => {
console.log('????');
return 100;
},
},
};
},
pathExistsSync: () => {
return true;
},
};

//set our mocks in place of usual require()
ch.__set__({
fs: fsMock,
});

const changes_hunter = new ch();

tap.test('checkLastModified - sets lastModified to fileTime ', function(test) {
//arrange
const mockPattern = { lastModified: 0 };
//act
changes_hunter.checkLastModified(mockPattern, {});

//assert
test.equals(mockPattern.lastModified, 100);
test.end();
});

tap.test(
'checkLastModified - does not alter pattern if file not found',
function(test) {
//arrange
const mockPattern = { lastModified: 1010 };
//act
changes_hunter.checkLastModified(mockPattern, null);

//assert
test.equals(mockPattern.lastModified, 1010);
test.end();
}
);

tap.test(
'checkLastModified - uses pattern.lastModified if greater than file time',
function(test) {
//arrange
const mockPattern = { lastModified: 101 };
//act
changes_hunter.checkLastModified(mockPattern, {});

//assert
test.equals(mockPattern.lastModified, 101);
test.end();
}
);