Skip to content

Commit

Permalink
Include the applicable exclusions when running upstream tests
Browse files Browse the repository at this point in the history
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/<test suite>.filter
  //brave/test/filters/<test suite>-<OS>.filter
  //brave/test/filters/<test suite>-<OS>-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.
  • Loading branch information
mariospr committed Mar 14, 2022
1 parent 7381557 commit 3ea5dfc
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions build/commands/lib/test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const fs = require('fs-extra')
const path = require('path')

const config = require('../lib/config')
Expand All @@ -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)
Expand Down Expand Up @@ -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`),
Expand Down

0 comments on commit 3ea5dfc

Please sign in to comment.