mirror of
https://github.com/react/react-native-devtools-frontend.git
synced 2026-09-28 13:13:37 +08:00
[testing] Use fixed paths to refer to snapshots/screenshots
This avoid special casing and passing golden locations around. In order to nicely reference snapshots, we move them next to the test files since snapshots are looked up by test name anyways. Bug: b:333423685 Change-Id: I02188633f25dffe8f863d64b1e769cbb5563b2b6 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/5435761 Reviewed-by: Simon Zünd <szuend@chromium.org> Reviewed-by: Jack Franklin <jacktfranklin@chromium.org> Commit-Queue: Philip Pfaffe <pfaffe@chromium.org>
This commit is contained in:
committed by
Devtools-frontend LUCI CQ
parent
ad75ffb2be
commit
ce5afc0d07
+1
-1
@@ -538,7 +538,7 @@ def _CheckObsoleteScreenshotGoldens(input_api, output_api):
|
||||
'scripts', 'test',
|
||||
'check_obsolete_goldens.js')
|
||||
|
||||
script_args = ["--interaction-test-root", interaction_test_root_path]
|
||||
script_args = []
|
||||
errors_from_script = _checkWithNodeScript(input_api, output_api,
|
||||
script_path, script_args)
|
||||
results.extend(errors_from_script)
|
||||
|
||||
@@ -10,14 +10,13 @@ const exec = util.promisify(childProcess.exec);
|
||||
|
||||
const yargsObject =
|
||||
require('yargs')
|
||||
.option('interaction-test-root', {type: 'string', desc: 'file path of the interaction test root directory.'})
|
||||
.option(
|
||||
'remove-files', {type: 'boolean', desc: 'Set to true to have obsolete goldens removed.', default: false})
|
||||
.argv;
|
||||
|
||||
const shouldRemoveFiles = yargsObject['remove-files'] === true;
|
||||
const interactionTestRoot = yargsObject['interaction-test-root'];
|
||||
|
||||
const SOURCE_ROOT = path.resolve(__dirname, path.join('..', '..'));
|
||||
const interactionTestRoot = path.join(SOURCE_ROOT, 'test', 'interactions');
|
||||
const GOLDENS_LOCATION = path.join(interactionTestRoot, 'goldens');
|
||||
|
||||
function findScreenshotsToCheck(folder) {
|
||||
|
||||
@@ -27,11 +27,10 @@ import {ScreenshotError} from '../shared/screenshot-error.js';
|
||||
* goldens from there.
|
||||
*/
|
||||
const testRunnerCWD = getTestRunnerConfigSetting<string>('cwd', '');
|
||||
const testSuiteSourceDir = getTestRunnerConfigSetting<string>('test-suite-source-dir', '');
|
||||
if (!testRunnerCWD || !testSuiteSourceDir) {
|
||||
if (!testRunnerCWD) {
|
||||
throw new Error('--cwd and --test-suite-source-dir must be provided when running the screenshot tests.');
|
||||
}
|
||||
const GOLDENS_FOLDER = path.join(testRunnerCWD, testSuiteSourceDir, 'goldens', platform);
|
||||
const GOLDENS_FOLDER = path.join(testRunnerCWD, 'test', 'interactions', 'goldens', platform);
|
||||
|
||||
/**
|
||||
* It's assumed that the image_diff binaries are in CWD/third_party/image_diff/{platform}/image_diff
|
||||
|
||||
@@ -4,22 +4,23 @@
|
||||
|
||||
import {assert} from 'chai';
|
||||
import {existsSync, mkdirSync, readFileSync, writeFileSync} from 'fs';
|
||||
import {basename, dirname, extname, join, normalize} from 'path';
|
||||
import {dirname, format, join, parse, relative} from 'path';
|
||||
|
||||
import {getTestRunnerConfigSetting} from '../conductor/test_runner_config.js';
|
||||
|
||||
const TARGET = getTestRunnerConfigSetting<string>('target', '');
|
||||
const CWD = getTestRunnerConfigSetting<string>('cwd', '');
|
||||
const TEST_SUITE_SOURCE_DIR = getTestRunnerConfigSetting<string>('test-suite-source-dir', '');
|
||||
const TEST_SUITE_PATH = getTestRunnerConfigSetting<string>('test-suite-path', '');
|
||||
if (!CWD || !TEST_SUITE_SOURCE_DIR) {
|
||||
throw new Error('--cwd and --test-suite-source-dir must be provided when running the snapshot tests.');
|
||||
if (!TARGET) {
|
||||
throw new Error('Unknown target');
|
||||
}
|
||||
if (!CWD) {
|
||||
throw new Error('--cwd must be provided when running the snapshot tests.');
|
||||
}
|
||||
if (!TEST_SUITE_PATH) {
|
||||
throw new Error('--test-suite-path must be specified');
|
||||
}
|
||||
|
||||
const SNAPSHOTS_DIR = join(CWD, TEST_SUITE_SOURCE_DIR, 'snapshots');
|
||||
|
||||
const UPDATE_SNAPSHOTS = Boolean(process.env['UPDATE_SNAPSHOTS']);
|
||||
|
||||
let currentTestPath: string|undefined;
|
||||
@@ -45,7 +46,7 @@ beforeEach(function() {
|
||||
currentTestTitle = currentTestTitle.slice(0, -match[1].length);
|
||||
}
|
||||
|
||||
currentTestPath = testPath && normalize(testPath.trim());
|
||||
currentTestPath = this.currentTest.file;
|
||||
|
||||
snapshotIndex = 0;
|
||||
}
|
||||
@@ -78,7 +79,10 @@ const restoreSnapshots = () => {
|
||||
};
|
||||
|
||||
const getSnapshotPath = (testPath: string) => {
|
||||
return join(SNAPSHOTS_DIR, dirname(testPath), `${basename(testPath, extname(testPath))}.json`);
|
||||
const relativeTestPath = parse(relative(join(CWD, 'out', TARGET, 'gen'), testPath));
|
||||
relativeTestPath.ext = '.json';
|
||||
relativeTestPath.base = `${relativeTestPath.name}.json`;
|
||||
return join(CWD, format(relativeTestPath));
|
||||
};
|
||||
|
||||
const getOrUpdateSnapshot = (value: unknown, options: SnapshotOptions) => {
|
||||
|
||||
Reference in New Issue
Block a user