Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate PL URLs for Diffy Visual Regression testing #926

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions services/drupal/web/themes/epa_theme/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ js/dist/*.map
dependencyGraph.json
.vscode
.idea
vrt_urls.txt
51 changes: 50 additions & 1 deletion services/drupal/web/themes/epa_theme/gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@ const lintPatternLab = require('./lib/lintPatternLab');
const writeFile = util.promisify(fs.writeFile);
const os = require('os');

const plumber = require('gulp-plumber');
const notify = require('gulp-notify');
const inject = require('gulp-inject');

const plumberErrorHandler = {
errorHandler: notify.onError({
title: 'Gulp',
message: 'Error: <%= error.message %>',
}),
};

const buildConfig = async () => {
const configDir = path.join(__dirname, '/source/_patterns/00-config');
const ymlDir = path.join(__dirname, './source/_data');
Expand Down Expand Up @@ -198,6 +209,43 @@ const buildPatterns = (exports.buildPatterns = series(
));
const buildImages = (exports.buildImages = createSprite);

const generateTestUrls = () => {
return src('vrt_urls-base.txt')
.pipe(plumber(plumberErrorHandler))
.pipe(
inject(src('./source/_patterns/**/*.twig', { read: false }), {
starttag: '<!-- startinject -->',
endtag: '<!-- endinject -->',
removeTags: true,
transform: (filepath, file, i, length) => {
const filepathClean = filepath.substr(9);
const parts = filepathClean
.replace(/[0-9]{1,2}-(?=[^\/]+\/)/gi, '')
.replace(/\.twig/gi, '')
.split('/');
let path = '';
let patternParts = '';
// Ignore any components in files or directories starting with underscore
for (let i=1; i < parts.length; i++) {
if (parts[i].startsWith('_')) {
return;
}
}
if (parts[3] === undefined) {
patternParts = `${parts[1]}-${parts[2]}`;
} else {
patternParts = `${parts[1]}-${parts[2]}-${parts[3]}`;
}
path = `${parts[0]}/${patternParts}/${patternParts}.rendered.html`;
const url = `https://www.epa.gov/themes/epa_theme/pattern-lab/${path}`;
return url;
},
})
)
.pipe(rename('vrt_urls.txt'))
.pipe(dest('.'));
};

const build = (isProduction = true) => {
const scriptTask = isProduction ? bundleScripts : bundleScriptsDev;
const stylesTask = isProduction ? compileStyles : compileStylesDev;
Expand All @@ -210,7 +258,8 @@ const build = (isProduction = true) => {
buildImages,
task('compileStyles'),
buildPatterns
)
),
generateTestUrls
);
};

Expand Down
Loading