diff --git a/package.json b/package.json index c7bef75..714fbe0 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/tests/test11/fixture/pancake/pancake.json b/tests/test11/fixture/pancake/pancake.json index 906dc9c..7298928 100644 --- a/tests/test11/fixture/pancake/pancake.json +++ b/tests/test11/fixture/pancake/pancake.json @@ -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"}}}} \ No newline at end of file +{"@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"}}}} \ No newline at end of file diff --git a/tests/test15/fixture/pancake/sass/pancake.scss b/tests/test15/fixture/pancake/sass/pancake.scss index 0c3831e..9d24ebc 100644 --- a/tests/test15/fixture/pancake/sass/pancake.scss +++ b/tests/test15/fixture/pancake/sass/pancake.scss @@ -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(); \ No newline at end of file +/*! 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(); \ No newline at end of file diff --git a/tests/test8/fixture/pancake/sass/pancake.scss b/tests/test8/fixture/pancake/sass/pancake.scss index 5725b97..8fb564a 100644 --- a/tests/test8/fixture/pancake/sass/pancake.scss +++ b/tests/test8/fixture/pancake/sass/pancake.scss @@ -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(); \ No newline at end of file +/*! 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(); \ No newline at end of file diff --git a/tests/test8/fixture/pancake/sass/testmodule1.scss b/tests/test8/fixture/pancake/sass/testmodule1.scss index ef0be65..801b0bd 100644 --- a/tests/test8/fixture/pancake/sass/testmodule1.scss +++ b/tests/test8/fixture/pancake/sass/testmodule1.scss @@ -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(); \ No newline at end of file +/*! 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(); \ No newline at end of file diff --git a/tests/test8/fixture/pancake/sass/testmodule2.scss b/tests/test8/fixture/pancake/sass/testmodule2.scss index 0c38d8e..742e798 100644 --- a/tests/test8/fixture/pancake/sass/testmodule2.scss +++ b/tests/test8/fixture/pancake/sass/testmodule2.scss @@ -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(); \ No newline at end of file +/*! 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(); \ No newline at end of file diff --git a/tests/test8/fixture/pancake/sass/testmodule3.scss b/tests/test8/fixture/pancake/sass/testmodule3.scss index 2f86114..b3a5ac8 100644 --- a/tests/test8/fixture/pancake/sass/testmodule3.scss +++ b/tests/test8/fixture/pancake/sass/testmodule3.scss @@ -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(); \ No newline at end of file +/*! 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(); \ No newline at end of file diff --git a/tests/test8/fixture/pancake/sass/testmodule4.scss b/tests/test8/fixture/pancake/sass/testmodule4.scss index 49f05f5..3bcd401 100644 --- a/tests/test8/fixture/pancake/sass/testmodule4.scss +++ b/tests/test8/fixture/pancake/sass/testmodule4.scss @@ -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(); \ No newline at end of file +/*! 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(); \ No newline at end of file diff --git a/tests/tester.js b/tests/tester.js index 58e38f8..06067d3 100644 --- a/tests/tester.js +++ b/tests/tester.js @@ -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 @@ -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 @@ -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 => { + 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 * @@ -345,7 +386,7 @@ const TESTER = (() => { //constructor factory sassVersion, jsVersion, reactVersion, - Path.normalize(`${ __dirname }/..`), + Path.normalize(`${ __dirname }`), ], allowEmptyPaths: true, encoding: 'utf8',