-
Notifications
You must be signed in to change notification settings - Fork 1
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
US152271 - Cleanup appropriate folders in the plugin during runs #36
Merged
Merged
Changes from 2 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
70bc105
Clear appropriate folders during runs
svanherk 731aeab
Missed cleanup
svanherk 11cbfac
Add comment
svanherk 7a05602
Simplify promise code
svanherk e3363ad
Switch to constants
svanherk 36ffa98
Merge branch 'US152271_Cleanup_Folders_Option_2' of github.com:Bright…
svanherk baecb3b
Merge branch 'main' into US152271_Cleanup_Folders_Option_2
svanherk 7f5c520
Code review refactors
svanherk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
import { access, constants, mkdir, rename, stat } from 'node:fs/promises'; | ||
import { dirname, join } from 'node:path'; | ||
import { access, constants, mkdir, readdir, rename, rm, stat } from 'node:fs/promises'; | ||
import { basename, dirname, join } from 'node:path'; | ||
import { env } from 'node:process'; | ||
|
||
const isCI = !!env['CI']; | ||
const DEFAULT_MARGIN = 10; | ||
|
||
async function checkFileExists(fileName) { | ||
|
@@ -12,6 +14,39 @@ async function checkFileExists(fileName) { | |
} | ||
} | ||
|
||
async function clearDir(updateGoldens, path) { | ||
if (updateGoldens) { | ||
await rm(path, { force: true, recursive: true }); | ||
} else { | ||
await rm(join(path, 'fail'), { force: true, recursive: true }); | ||
await rm(join(path, 'pass'), { force: true, recursive: true }); | ||
await rm(join(path, 'report.html'), { force: true }); | ||
dlockhart marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} | ||
|
||
async function clearAllDirs(updateGoldens, vdiffPath) { | ||
if (updateGoldens) { | ||
await rm(vdiffPath, { force: true, recursive: true }); | ||
} else { | ||
await clearDiffPaths(vdiffPath); | ||
} | ||
} | ||
|
||
async function clearDiffPaths(dir) { | ||
const paths = await readdir(dir, { withFileTypes: true }); | ||
for (const path of paths) { | ||
const full = join(dir, path.name); | ||
const base = basename(path.name); | ||
|
||
if (path.isDirectory()) { | ||
if (base === 'pass' || base === 'fail') await rm(full, { force: true, recursive: true }); | ||
else await clearDiffPaths(full); | ||
} else { | ||
if (base === 'report.html') await rm(full, { force: true }); | ||
} | ||
} | ||
} | ||
|
||
async function tryMoveFile(srcFileName, destFileName) { | ||
await mkdir(dirname(destFileName), { recursive: true }); | ||
try { | ||
|
@@ -42,12 +77,17 @@ function extractTestPartsFromName(name) { | |
}; | ||
} | ||
|
||
export function visualDiff({ updateGoldens = false } = {}) { | ||
let rootDir; | ||
export function visualDiff({ updateGoldens = false, runSubset = false } = {}) { | ||
let currentRun = 0, | ||
rootDir; | ||
const clearedDirs = new Map(); | ||
return { | ||
name: 'brightspace-visual-diff', | ||
async serverStart({ config }) { | ||
rootDir = config.rootDir; | ||
|
||
if (runSubset || isCI) return; | ||
await clearAllDirs(updateGoldens, join(rootDir, '.vdiff')); | ||
}, | ||
async executeCommand({ command, payload, session }) { | ||
|
||
|
@@ -61,9 +101,27 @@ export function visualDiff({ updateGoldens = false } = {}) { | |
const browser = session.browser.name.toLowerCase(); | ||
const { dir, newName } = extractTestPartsFromName(payload.name); | ||
const testPath = dirname(session.testFile).replace(rootDir, ''); | ||
const goldenFileName = `${join(rootDir, '.vdiff', testPath, 'golden', browser, dir, newName)}.png`; | ||
const passFileName = `${join(rootDir, '.vdiff', testPath, 'pass', browser, dir, newName)}.png`; | ||
const screenshotFileName = `${join(rootDir, '.vdiff', testPath, 'fail', browser, dir, newName)}.png`; | ||
const newPath = join(rootDir, '.vdiff', testPath, dir); | ||
const goldenFileName = `${join(newPath, 'golden', browser, newName)}.png`; | ||
const passFileName = `${join(newPath, 'pass', browser, newName)}.png`; | ||
const screenshotFileName = `${join(newPath, 'fail', browser, newName)}.png`; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This switches to the new directory structure we settled on in slack |
||
|
||
if (!isCI) { // CI will be a fresh .vdiff folder each time and only one run | ||
if (session.testRun !== currentRun) { | ||
currentRun = session.testRun; | ||
clearedDirs.clear(); | ||
} | ||
|
||
if (runSubset || currentRun > 0) { | ||
if (!clearedDirs.has(newPath)) { | ||
const promise = clearDir(updateGoldens, newPath); | ||
clearedDirs.set(newPath, promise); | ||
await promise; | ||
} else { | ||
await clearedDirs.get(newPath); | ||
} | ||
svanherk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} | ||
|
||
const opts = payload.opts || {}; | ||
opts.margin = opts.margin || DEFAULT_MARGIN; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added this to make CI as quick as possible, but we could leave it out if we'd rather keep things simple. It'll just search for
fail
,pass
, andreports
that won't exist.