From ac023122ec92e3f74f598a7d20054c8c96313c90 Mon Sep 17 00:00:00 2001 From: Mario Sanchez Prada Date: Tue, 11 Jan 2022 12:02:57 +0100 Subject: [PATCH] Include the applicable exclusions when running upstream tests This adds support in the `npm run test` command when running upstream tests so that any test filters file that can be applied to the current test suite will be applied to avoid certain tests from running. This means that `npm run test` will automatically add the relevant --test-launcher-filter-file parameter if at least one of the following files are present on-disk at the time of running the tests: //brave/test/filters/.filter //brave/test/filters/-.filter //brave/test/filters/--arch.filter In case multiple files are available, all of them will be used along with the --test-launcher-filter-file parameter, so that we can provide a base filters file for all platforms and then refine it with more exclusions for specific platforms and architectures. --- build/commands/lib/test.js | 44 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/build/commands/lib/test.js b/build/commands/lib/test.js index f2e9501dc6bc..43808a14b514 100644 --- a/build/commands/lib/test.js +++ b/build/commands/lib/test.js @@ -1,3 +1,4 @@ +const fs = require('fs-extra') const path = require('path') const config = require('../lib/config') @@ -20,6 +21,38 @@ const getTestsToRun = (config, suite) => { return testsToRun } +// Returns a list of paths to files containing all the filters that would apply +// to the current test suite, as long as such files exist in the filesystem. +// +// For instance, for Windows 64-bit and assuming all the filters files exist +// in the filesystem, this method would return paths to the following files: +// - unit-tests.filter -> Base filters +// - unit_tests-windows.filters: -> Platform specific +// - unit_tests-windows-x86.filters -> Platform & Architecture specific +const getApplicableFilters = (suite) => { + let filterFilePaths = [] + + let targetPlatform = process.platform + if (targetPlatform === "win32") { + targetPlatform = "windows" + } else if (targetPlatform === "darwin") { + targetPlatform = "macos" + } + + let possibleFilters = [ + suite, + [suite, targetPlatform].join('-'), + [suite, targetPlatform, config.targetArch].join('-'), + ] + possibleFilters.forEach(filterName => { + let filterFilePath = path.join(config.braveCoreDir, 'test', 'filters', `${filterName}.filter`) + if (fs.existsSync(filterFilePath)) + filterFilePaths.push(filterFilePath) + }); + + return filterFilePaths +} + const test = (passthroughArgs, suite, buildConfig = config.defaultBuildConfig, options) => { config.buildConfig = buildConfig config.update(options) @@ -76,6 +109,17 @@ const test = (passthroughArgs, suite, buildConfig = config.defaultBuildConfig, o } util.buildTarget() + // Filter out upstream tests that are known to fail for Brave + let upstreamTestSuites = [ + 'unit_tests', + 'browser_tests', + ] + if (upstreamTestSuites.includes(suite)) { + let filterFilePaths = getApplicableFilters(suite) + if (filterFilePaths.length > 0) + braveArgs.push(`--test-launcher-filter-file="${filterFilePaths.join(';')}"`) + } + if (config.targetOS === 'ios') { util.run(path.join(config.outputDir, "iossim"), [ path.join(config.outputDir, `${suite}.app`),