Skip to content

Commit

Permalink
DS-28: Remove VRT-related JS from testing tools
Browse files Browse the repository at this point in the history
  • Loading branch information
danielamorse committed Apr 14, 2021
1 parent 6084311 commit 121a48f
Show file tree
Hide file tree
Showing 8 changed files with 5 additions and 250 deletions.
5 changes: 1 addition & 4 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,7 @@ module.exports = {
],
globalSetup: './packages/testing/testing-jest/jest-global-setup.js',
globalTeardown: './packages/testing/testing-jest/jest-global-teardown.js',
setupFilesAfterEnv: [
'./packages/testing/testing-jest/jest-setup-files-after-env.js',
'jest-expect-message',
],
setupFilesAfterEnv: ['jest-dom/extend-expect', 'jest-expect-message'],
snapshotSerializers: ['jest-serializer-html'],
reporters: [
'default',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,6 @@ describe('Test', () => {
const renderedHTML = await html(outerHTML);
expect(renderedHTML).toMatchSnapshot();
const image = await page.screenshot();
expect(image).toMatchImageSnapshot(vrtDefaultConfig);
});
test('renders without Shadow DOM', async function() {
Expand All @@ -262,9 +259,6 @@ describe('Test', () => {
const renderedHTML = await html(outerHTML);
expect(renderedHTML).toMatchSnapshot();
const image = await page.screenshot();
expect(image).toMatchImageSnapshot(vrtDefaultConfig);
});
test(\`sets 'disabled' prop\`, async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,6 @@ describe('<%= props.name.titleCase %>', () => {

const renderedHTML = await html(outerHTML);
expect(renderedHTML).toMatchSnapshot();

const image = await page.screenshot();
expect(image).toMatchImageSnapshot(vrtDefaultConfig);
});

test('renders without Shadow DOM', async function() {
Expand All @@ -92,9 +89,6 @@ describe('<%= props.name.titleCase %>', () => {

const renderedHTML = await html(outerHTML);
expect(renderedHTML).toMatchSnapshot();

const image = await page.screenshot();
expect(image).toMatchImageSnapshot(vrtDefaultConfig);
});

test(`sets 'disabled' prop`, async () => {
Expand Down
142 changes: 0 additions & 142 deletions packages/testing/testing-jest/jest-reporter-vrt.js
Original file line number Diff line number Diff line change
@@ -1,41 +1,7 @@
#!/usr/bin/env node
const chalk = require('chalk');
const fs = require('fs');
const path = require('path');
const { upload } = require('now-storage');
const { promisify } = require('util');
const boxen = require('boxen');
const terminalLink = require('terminal-link');

const vrtScreenshots = [];

async function uploadImage(name, content) {
const { url } = await upload(
process.env.NOW_TOKEN,
{
name,
content,
},
{ teamId: 'boltdesignsystem' },
);
return url;
}

const NOW_TOKEN = process.env.NOW_TOKEN;
// let filesToUpload = [];

// async function finishUploading() {
// const { url } = await multiUpload(process.env.NOW_TOKEN, filesToUpload, {
// deploymentName: 'bolt-jest-vrt',
// });
// return url;
// }
async function asyncForEach(array, callback) {
for (let index = 0; index < array.length; index++) {
// eslint-disable-next-line no-await-in-loop
await callback(array[index], index, array);
}
}

class JestScreenshotReporter {
constructor(globalConfig, options) {
Expand Down Expand Up @@ -69,13 +35,6 @@ ${pathsToFailingTests.join('\n')}
`;
}

if (vrtScreenshots.length >= 1) {
summaryOfVrtResults = `
${chalk.bold('These are the VRT diff screenshots for tests that are failing:')}
${vrtScreenshots.join('\n')}
`;
}

console.log(
boxen(testSummary + summaryOfFailingTests + summaryOfVrtResults, {
padding: 1,
Expand All @@ -84,107 +43,6 @@ ${vrtScreenshots.join('\n')}
}),
);
}

onTestResult(test, testResult, aggregateResults) {
if (
testResult.numFailingTests &&
testResult.failureMessage.match(/different from snapshot/)
) {
return new Promise(async (resolveAll, reject) => {
const allImagePromises = [];

const testingDir = path.dirname(testResult.testFilePath);
const filesToProcess = fs.readdirSync(
path.join(testingDir, '/__image_snapshots__/__diff_output__/'),
);

filesToProcess.forEach(file => {
const filePromise = new Promise(async function(resolve, reject) {
const imageData = fs.readFileSync(
path.join(
testingDir,
`/__image_snapshots__/__diff_output__/${file}`,
),
);

// exit early so local Jest tests without the necessary now.sh token exit when a failure occurs
if (!NOW_TOKEN) {
const urlToDisplay = path.relative(
process.cwd(),
path.join(
testingDir,
`/__image_snapshots__/__diff_output__/${file}`,
),
);
resolve(urlToDisplay);
} else {
uploadImage(file, imageData).then(url => {
const urlToDisplay = `https://${url}/${file}`;
resolve(urlToDisplay);
});
}
});
allImagePromises.push(filePromise);
});

if (NOW_TOKEN) {
return Promise.all(allImagePromises)
.then(function(screenshotDiffs) {
screenshotDiffs.forEach(screenshot => {
vrtScreenshots.push(
`• ${terminalLink(
screenshot.substring(
screenshot.lastIndexOf('/') + 1,
screenshot.length,
),
screenshot,
)}`,
);
});
console.log(
chalk.red.bold(
`Uploaded VRT image diff(s) to: \n${screenshotDiffs.join(
'\n',
)}`,
),
);
resolveAll(screenshotDiffs);
})
.catch(err => {
console.log(
chalk.red.bold(
`Error uploading image diff(s) to now.sh: ${err}`,
),
);
});
} else {
return Promise.all(allImagePromises)
.then(function(screenshotDiffs) {
screenshotDiffs.forEach(screenshot => {
vrtScreenshots.push(
`• ${terminalLink(
screenshot.substring(
screenshot.lastIndexOf('/') + 1,
screenshot.length,
),
screenshot,
)}`,
);
});

resolveAll(screenshotDiffs);
})
.catch(err => {
console.log(
chalk.red.bold(
`Error encountered when processing local image VRT diff(s): ${err}`,
),
);
});
}
});
}
}
}

module.exports = JestScreenshotReporter;
4 changes: 0 additions & 4 deletions packages/testing/testing-jest/jest-setup-files-after-env.js

This file was deleted.

5 changes: 1 addition & 4 deletions packages/testing/testing-jest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,10 @@
"jest-dom": "^3.3.0",
"jest-environment-node": "^24.9.0",
"jest-expect-message": "^1.0.2",
"jest-image-snapshot": "^2.11.1",
"jest-serializer-html": "^7.0.0",
"now-storage": "^1.3.0",
"prettier": "^1.18.2",
"puppeteer": "^2.1.0",
"raf": "^3.4.1",
"terminal-link": "^1.3.0"
"raf": "^3.4.1"
},
"optionalDependencies": {
"lit-html": "^1.0.0"
Expand Down
20 changes: 0 additions & 20 deletions patches/jest-image-snapshot+2.12.0.patch

This file was deleted.

Loading

0 comments on commit 121a48f

Please sign in to comment.