Skip to content
This repository has been archived by the owner on Aug 26, 2021. It is now read-only.

Commit

Permalink
Added tester step to normalize fixtures, corrected test fixture pathing
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam A. Zerella committed Mar 25, 2019
1 parent 90e36b5 commit 78d43e2
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 16 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"copy-dir": "^0.4.0",
"del": "^4.0.0",
"dirsum": "^0.1.1",
"fs-readdir-recursive": "^1.1.0",
"jest-cli": "^24.5.0",
"onchange": "^5.2.0",
"replace-in-file": "^3.4.4",
Expand Down
2 changes: 1 addition & 1 deletion tests/test11/fixture/pancake/pancake.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"@gov.au/testmodule1":{"name":"@gov.au/testmodule1","version":"11.0.1","dependencies":{},"path":"C:\\Users\\Adam\\dev\\pancake\\tests\\test11\\node_modules\\@gov.au\\testmodule1","settings":{"version":"1.0.0","plugins":["@gov.au/pancake-sass","@gov.au/pancake-js","@gov.au/pancake-json"],"sass":{"path":"lib/sass/_module.scss","sass-versioning":true},"js":{"path":"lib/js/module.js"}}},"@gov.au/testmodule2":{"name":"@gov.au/testmodule2","version":"13.0.0","dependencies":{"@gov.au/testmodule1":"^11.0.1"},"path":"C:\\Users\\Adam\\dev\\pancake\\tests\\test11\\node_modules\\@gov.au\\testmodule2","settings":{"version":"1.0.0","plugins":["@gov.au/pancake-sass","@gov.au/pancake-js","@gov.au/pancake-json"],"sass":{"path":"lib/sass/_module.scss","sass-versioning":true},"js":{"path":"lib/js/module.js"}}}}
{"@gov.au/testmodule1":{"name":"@gov.au/testmodule1","version":"11.0.1","dependencies":{},"path":"[path]/test11/node_modules/@gov.au/testmodule1","settings":{"version":"1.0.0","plugins":["@gov.au/pancake-sass","@gov.au/pancake-js","@gov.au/pancake-json"],"sass":{"path":"lib/sass/_module.scss","sass-versioning":true},"js":{"path":"lib/js/module.js"}}},"@gov.au/testmodule2":{"name":"@gov.au/testmodule2","version":"13.0.0","dependencies":{"@gov.au/testmodule1":"^11.0.1"},"path":"[path]/test11/node_modules/@gov.au/testmodule2","settings":{"version":"1.0.0","plugins":["@gov.au/pancake-sass","@gov.au/pancake-js","@gov.au/pancake-json"],"sass":{"path":"lib/sass/_module.scss","sass-versioning":true},"js":{"path":"lib/js/module.js"}}}}
2 changes: 1 addition & 1 deletion tests/test15/fixture/pancake/sass/pancake.scss
Original file line number Diff line number Diff line change
@@ -1 +1 @@
/*! PANCAKE v1.4.1 PANCAKE-SASS v2.3.4 *//* * THIS FILE IS AUTOGENERATED EVERY TIME YOU INSTALL A PANCAKE MODULE. * DO NOT EDIT THIS FILE AND AVOID COMMITTING IT TO VERSION CONTROL. */@import "C:\\Users\\Adam\\dev\\pancake\\tests\\test15\\node_modules\\sass-versioning\\dist\\_index.scss";@import "C:\\Users\\Adam\\dev\\pancake\\tests\\test15\\node_modules\\@gov.au\\testmodule2\\lib\\sass\\_module.scss";@include versioning-check();
/*! PANCAKE v1.4.1 PANCAKE-SASS v2.3.4 *//* * THIS FILE IS AUTOGENERATED EVERY TIME YOU INSTALL A PANCAKE MODULE. * DO NOT EDIT THIS FILE AND AVOID COMMITTING IT TO VERSION CONTROL. */@import "[path]/test15/node_modules/sass-versioning/dist/_index.scss";@import "[path]/test15/node_modules/@gov.au/testmodule2/lib/sass/_module.scss";@include versioning-check();
2 changes: 1 addition & 1 deletion tests/test8/fixture/pancake/sass/pancake.scss
Original file line number Diff line number Diff line change
@@ -1 +1 @@
/*! PANCAKE v1.4.1 PANCAKE-SASS v2.3.4 *//* * THIS FILE IS AUTOGENERATED EVERY TIME YOU INSTALL A PANCAKE MODULE. * DO NOT EDIT THIS FILE AND AVOID COMMITTING IT TO VERSION CONTROL. */@import "C:\\Users\\Adam\\dev\\pancake\\tests\\test8\\node_modules\\sass-versioning\\dist\\_index.scss";@import "C:\\Users\\Adam\\dev\\pancake\\tests\\test8\\node_modules\\@gov.au\\testmodule1\\lib\\sass\\_module.scss";@import "C:\\Users\\Adam\\dev\\pancake\\tests\\test8\\node_modules\\@gov.au\\testmodule3\\lib\\sass\\_module.scss";@import "C:\\Users\\Adam\\dev\\pancake\\tests\\test8\\node_modules\\@gov.au\\testmodule4\\lib\\sass\\_module.scss";@import "C:\\Users\\Adam\\dev\\pancake\\tests\\test8\\node_modules\\@gov.au\\testmodule2\\lib\\sass\\_module.scss";@include versioning-check();
/*! PANCAKE v1.4.1 PANCAKE-SASS v2.3.4 *//* * THIS FILE IS AUTOGENERATED EVERY TIME YOU INSTALL A PANCAKE MODULE. * DO NOT EDIT THIS FILE AND AVOID COMMITTING IT TO VERSION CONTROL. */@import "[path]/test8/node_modules/sass-versioning/dist/_index.scss";@import "[path]/test8/node_modules/@gov.au/testmodule1/lib/sass/_module.scss";@import "[path]/test8/node_modules/@gov.au/testmodule3/lib/sass/_module.scss";@import "[path]/test8/node_modules/@gov.au/testmodule4/lib/sass/_module.scss";@import "[path]/test8/node_modules/@gov.au/testmodule2/lib/sass/_module.scss";@include versioning-check();
2 changes: 1 addition & 1 deletion tests/test8/fixture/pancake/sass/testmodule1.scss
Original file line number Diff line number Diff line change
@@ -1 +1 @@
/*! PANCAKE v1.4.1 PANCAKE-SASS v2.3.4 *//* * THIS FILE IS AUTOGENERATED EVERY TIME YOU INSTALL A PANCAKE MODULE. * DO NOT EDIT THIS FILE AND AVOID COMMITTING IT TO VERSION CONTROL. *//* @gov.au/testmodule1 v11.0.1 */@import "C:\\Users\\Adam\\dev\\pancake\\tests\\test8\\node_modules\\sass-versioning\\dist\\_index.scss";@import "C:\\Users\\Adam\\dev\\pancake\\tests\\test8\\node_modules\\@gov.au\\testmodule1\\lib\\sass\\_module.scss";@include versioning-check();
/*! PANCAKE v1.4.1 PANCAKE-SASS v2.3.4 *//* * THIS FILE IS AUTOGENERATED EVERY TIME YOU INSTALL A PANCAKE MODULE. * DO NOT EDIT THIS FILE AND AVOID COMMITTING IT TO VERSION CONTROL. *//* @gov.au/testmodule1 v11.0.1 */@import "[path]/test8/node_modules/sass-versioning/dist/_index.scss";@import "[path]/test8/node_modules/@gov.au/testmodule1/lib/sass/_module.scss";@include versioning-check();
2 changes: 1 addition & 1 deletion tests/test8/fixture/pancake/sass/testmodule2.scss
Original file line number Diff line number Diff line change
@@ -1 +1 @@
/*! PANCAKE v1.4.1 PANCAKE-SASS v2.3.4 *//* * THIS FILE IS AUTOGENERATED EVERY TIME YOU INSTALL A PANCAKE MODULE. * DO NOT EDIT THIS FILE AND AVOID COMMITTING IT TO VERSION CONTROL. *//* @gov.au/testmodule2 v13.0.0 */@import "C:\\Users\\Adam\\dev\\pancake\\tests\\test8\\node_modules\\sass-versioning\\dist\\_index.scss";@import "C:\\Users\\Adam\\dev\\pancake\\tests\\test8\\node_modules\\@gov.au\\testmodule1\\lib\\sass\\_module.scss";@import "C:\\Users\\Adam\\dev\\pancake\\tests\\test8\\node_modules\\@gov.au\\testmodule3\\lib\\sass\\_module.scss";@import "C:\\Users\\Adam\\dev\\pancake\\tests\\test8\\node_modules\\@gov.au\\testmodule4\\lib\\sass\\_module.scss";@import "C:\\Users\\Adam\\dev\\pancake\\tests\\test8\\node_modules\\@gov.au\\testmodule2\\lib\\sass\\_module.scss";@include versioning-check();
/*! PANCAKE v1.4.1 PANCAKE-SASS v2.3.4 *//* * THIS FILE IS AUTOGENERATED EVERY TIME YOU INSTALL A PANCAKE MODULE. * DO NOT EDIT THIS FILE AND AVOID COMMITTING IT TO VERSION CONTROL. *//* @gov.au/testmodule2 v13.0.0 */@import "[path]/test8/node_modules/sass-versioning/dist/_index.scss";@import "[path]/test8/node_modules/@gov.au/testmodule1/lib/sass/_module.scss";@import "[path]/test8/node_modules/@gov.au/testmodule3/lib/sass/_module.scss";@import "[path]/test8/node_modules/@gov.au/testmodule4/lib/sass/_module.scss";@import "[path]/test8/node_modules/@gov.au/testmodule2/lib/sass/_module.scss";@include versioning-check();
2 changes: 1 addition & 1 deletion tests/test8/fixture/pancake/sass/testmodule3.scss
Original file line number Diff line number Diff line change
@@ -1 +1 @@
/*! PANCAKE v1.4.1 PANCAKE-SASS v2.3.4 *//* * THIS FILE IS AUTOGENERATED EVERY TIME YOU INSTALL A PANCAKE MODULE. * DO NOT EDIT THIS FILE AND AVOID COMMITTING IT TO VERSION CONTROL. *//* @gov.au/testmodule3 v11.0.0 */@import "C:\\Users\\Adam\\dev\\pancake\\tests\\test8\\node_modules\\sass-versioning\\dist\\_index.scss";@import "C:\\Users\\Adam\\dev\\pancake\\tests\\test8\\node_modules\\@gov.au\\testmodule1\\lib\\sass\\_module.scss";@import "C:\\Users\\Adam\\dev\\pancake\\tests\\test8\\node_modules\\@gov.au\\testmodule3\\lib\\sass\\_module.scss";@include versioning-check();
/*! PANCAKE v1.4.1 PANCAKE-SASS v2.3.4 *//* * THIS FILE IS AUTOGENERATED EVERY TIME YOU INSTALL A PANCAKE MODULE. * DO NOT EDIT THIS FILE AND AVOID COMMITTING IT TO VERSION CONTROL. *//* @gov.au/testmodule3 v11.0.0 */@import "[path]/test8/node_modules/sass-versioning/dist/_index.scss";@import "[path]/test8/node_modules/@gov.au/testmodule1/lib/sass/_module.scss";@import "[path]/test8/node_modules/@gov.au/testmodule3/lib/sass/_module.scss";@include versioning-check();
2 changes: 1 addition & 1 deletion tests/test8/fixture/pancake/sass/testmodule4.scss
Original file line number Diff line number Diff line change
@@ -1 +1 @@
/*! PANCAKE v1.4.1 PANCAKE-SASS v2.3.4 *//* * THIS FILE IS AUTOGENERATED EVERY TIME YOU INSTALL A PANCAKE MODULE. * DO NOT EDIT THIS FILE AND AVOID COMMITTING IT TO VERSION CONTROL. *//* @gov.au/testmodule4 v11.0.0 */@import "C:\\Users\\Adam\\dev\\pancake\\tests\\test8\\node_modules\\sass-versioning\\dist\\_index.scss";@import "C:\\Users\\Adam\\dev\\pancake\\tests\\test8\\node_modules\\@gov.au\\testmodule1\\lib\\sass\\_module.scss";@import "C:\\Users\\Adam\\dev\\pancake\\tests\\test8\\node_modules\\@gov.au\\testmodule3\\lib\\sass\\_module.scss";@import "C:\\Users\\Adam\\dev\\pancake\\tests\\test8\\node_modules\\@gov.au\\testmodule4\\lib\\sass\\_module.scss";@include versioning-check();
/*! PANCAKE v1.4.1 PANCAKE-SASS v2.3.4 *//* * THIS FILE IS AUTOGENERATED EVERY TIME YOU INSTALL A PANCAKE MODULE. * DO NOT EDIT THIS FILE AND AVOID COMMITTING IT TO VERSION CONTROL. *//* @gov.au/testmodule4 v11.0.0 */@import "[path]/test8/node_modules/sass-versioning/dist/_index.scss";@import "[path]/test8/node_modules/@gov.au/testmodule1/lib/sass/_module.scss";@import "[path]/test8/node_modules/@gov.au/testmodule3/lib/sass/_module.scss";@import "[path]/test8/node_modules/@gov.au/testmodule4/lib/sass/_module.scss";@include versioning-check();
59 changes: 50 additions & 9 deletions tests/tester.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@
//--------------------------------------------------------------------------------------------------------------------------------------------------------------
// Dependencies
//--------------------------------------------------------------------------------------------------------------------------------------------------------------
const Replace = require('replace-in-file');
const Spawn = require('child_process');
const Copydir = require('copy-dir');
const Dirsum = require('dirsum');
const Chalk = require('chalk');
const Path = require('path');
const Del = require('del');
const Fs = require(`fs`);
const Spawn = require( 'child_process' );
const Path = require( 'path' );
const Fs = require( 'fs' );

const Readdir = require( 'fs-readdir-recursive' );
const Replace = require( 'replace-in-file' );
const Copydir = require( 'copy-dir' );
const Dirsum = require( 'dirsum' );
const Chalk = require( 'chalk' );
const Del = require( 'del' );

//--------------------------------------------------------------------------------------------------------------------------------------------------------------
// GLOBALS
Expand Down Expand Up @@ -213,6 +214,7 @@ const TESTER = (() => { //constructor factory
TESTER
.delete( scriptFolder, unit ) //delete trash first
.then( () => TESTER.copyFixtures( scriptFolder, unit ) ) //copy fixtures
.then( () => TESTER.normalizeFixtures( scriptFolder, unit ) ) //correct platform pathing
.then( () => TESTER.replaceFixtures( scriptFolder, unit ) ) //compile fixtures
.then( () => TESTER.run( scriptFolder, unit ) ) //now run script
.then( () => TESTER.fixture( scriptFolder, unit ) ) //get hash for fixture
Expand Down Expand Up @@ -310,6 +312,45 @@ const TESTER = (() => { //constructor factory
},


/**
* Replace fixture [path] items with platform specific pathing
*
* @param {string} path - The path to the folder that needs cleaning
* @param {object} settings - The settings object for this test
*
* @return {Promise object}
*/
normalizeFixtures: ( path, settings ) => {
return new Promise( ( resolve, reject ) => {
if( settings.empty ) {
resolve();
}
else {
let fixturePath = Path.normalize( `${ path }/_fixture/` );
let fixtures = Readdir( fixturePath )

fixtures.forEach( item => {
let filePath = Path.join( `${ path }/_fixture/`, item );
let fileData = Fs.readFileSync( filePath, `utf-8` );
let matches = fileData.match( /\[path\].+?"/gm );

if( matches !== null ){
matches.forEach( match => {
// console.log( `REPLACING ${ match } WITH ${ Path.win32.normalize( match ) }`)
let normalizedFileData = fileData.replace( new RegExp( match, "gm" ), Path.normalize( match ) );
Fs.writeFile( filePath, normalizedFileData, `utf-8`, ( error ) => {
if( error ) reject( error );
});
});
}
});

resolve();
}
})
},


/**
* Replace placeholders in temp fixtures
*
Expand Down Expand Up @@ -345,7 +386,7 @@ const TESTER = (() => { //constructor factory
sassVersion,
jsVersion,
reactVersion,
Path.normalize(`${ __dirname }/..`),
Path.normalize(`${ __dirname }`),
],
allowEmptyPaths: true,
encoding: 'utf8',
Expand Down

0 comments on commit 78d43e2

Please sign in to comment.