-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Multiple modules: clean up unit tests (#11630)
* Test chunking * update some bidder eid tests * split eid tests into each userId submodule * cleanup userId_spec * add TEST_PAT config * fix idx, lmp * clean up userId_spec * fix double run, invibes, intentIq * small fixes * undo package-lock changes * update colors, remove empty test * 8pod analytics: clean up interval handler
- Loading branch information
Showing
47 changed files
with
1,397 additions
and
2,210 deletions.
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
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,23 +1,97 @@ | ||
const karma = require('karma'); | ||
const process = require('process'); | ||
const karmaConfMaker = require('./karma.conf.maker.js'); | ||
const glob = require('glob'); | ||
/** | ||
* Environment variables: | ||
* | ||
* TEST_CHUNKS: number of chunks to split tests into, or MAX to run each test suite in isolation | ||
* TEST_CHUNK: run only this chunk (e.g. TEST_CHUNKS=4 TEST_CHUNK=2 gulp test) will run only the second quarter | ||
* TEST_ALL: set to continue running remaining chunks after a previous chunk failed | ||
* TEST_PAT: test file pattern (default is *_spec.js) | ||
*/ | ||
|
||
process.on('message', function(options) { | ||
try { | ||
let cfg = karmaConfMaker(options.coverage, options.browserstack, options.watch, options.file, options.disableFeatures); | ||
process.on('message', function (options) { | ||
function info(msg) { | ||
// eslint-disable-next-line no-console | ||
console.log('\x1b[46m\x1b[30m%s\x1b[0m', msg); | ||
} | ||
|
||
function error(msg) { | ||
// eslint-disable-next-line no-console | ||
console.log('\x1b[41m\x1b[37m%s\x1b[0m', msg); | ||
} | ||
|
||
function chunkDesc(chunk) { | ||
return chunk.length > 1 ? `From ${chunk[0]} to ${chunk[chunk.length - 1]}` : chunk[0]; | ||
} | ||
|
||
const failures = []; | ||
|
||
function quit(fail) { | ||
// eslint-disable-next-line no-console | ||
console.log(''); | ||
failures.forEach(([chunkNo, chunkTot, chunk]) => { | ||
error(`Chunk ${chunkNo + 1} of ${chunkTot} failed: ${chunkDesc(chunk)}`); | ||
fail = true; | ||
}); | ||
process.exit(fail ? 1 : 0); | ||
} | ||
|
||
process.on('SIGINT', () => quit()); | ||
|
||
function runKarma(file) { | ||
let cfg = karmaConfMaker(options.coverage, options.browserstack, options.watch, file, options.disableFeatures); | ||
if (options.browsers && options.browsers.length) { | ||
cfg.browsers = options.browsers; | ||
} | ||
if (options.oneBrowser) { | ||
cfg.browsers = [cfg.browsers.find((b) => b.toLowerCase().includes(options.oneBrowser.toLowerCase())) || cfg.browsers[0]] | ||
cfg.browsers = [cfg.browsers.find((b) => b.toLowerCase().includes(options.oneBrowser.toLowerCase())) || cfg.browsers[0]]; | ||
} | ||
cfg = karma.config.parseConfig(null, cfg); | ||
new karma.Server(cfg, (exitCode) => { | ||
process.exit(exitCode); | ||
}).start(); | ||
return new Promise((resolve, reject) => { | ||
new karma.Server(cfg, (exitCode) => { | ||
exitCode ? reject(exitCode) : resolve(exitCode); | ||
}).start(); | ||
}); | ||
} | ||
|
||
try { | ||
let chunks = []; | ||
if (options.file) { | ||
chunks.push([options.file]); | ||
} else { | ||
const chunkNum = process.env['TEST_CHUNKS'] ?? 1; | ||
const pat = process.env['TEST_PAT'] ?? '*_spec.js' | ||
const tests = glob.sync('test/**/' + pat).sort(); | ||
const chunkLen = chunkNum === 'MAX' ? 0 : Math.floor(tests.length / Number(chunkNum)); | ||
chunks.push([]); | ||
tests.forEach((fn) => { | ||
chunks[chunks.length - 1].push(fn); | ||
if (chunks[chunks.length - 1].length > chunkLen) chunks.push([]); | ||
}); | ||
chunks = chunks.filter(chunk => chunk.length > 0); | ||
if (chunks.length > 1) { | ||
info(`Splitting tests into ${chunkNum} chunks, ${chunkLen + 1} suites each`); | ||
} | ||
} | ||
let pm = Promise.resolve(); | ||
chunks.forEach((chunk, i) => { | ||
if (process.env['TEST_CHUNK'] && Number(process.env['TEST_CHUNK']) !== i + 1) return; | ||
pm = pm.then(() => { | ||
info(`Starting chunk ${i + 1} of ${chunks.length}: ${chunkDesc(chunk)}`); | ||
return runKarma(chunk); | ||
}).catch(() => { | ||
failures.push([i, chunks.length, chunk]); | ||
if (!process.env['TEST_ALL']) quit(); | ||
}).finally(() => { | ||
info(`Chunk ${i + 1} of ${chunks.length}: done`); | ||
}); | ||
}); | ||
pm.then(() => quit()); | ||
} catch (e) { | ||
// eslint-disable-next-line | ||
console.error(e); | ||
process.exit(1); | ||
error(e); | ||
quit(true); | ||
} | ||
}); |
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
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
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
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
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export function clearAllCookies() { | ||
document.cookie.split(';').forEach(function (c) { | ||
document.cookie = c.replace(/^ +/, '').replace(/=.*/, '=;expires=' + new Date().toUTCString() + ';path=/'); | ||
}); | ||
} |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
[it, describe].forEach((ob) => { | ||
ob.only = function () { | ||
[ | ||
'describe.only and it.only are disabled unless you provide a single spec --file,', | ||
'because they can silently break the pipeline tests', | ||
// eslint-disable-next-line no-console | ||
].forEach(l => console.error(l)) | ||
throw new Error('do not use .only()') | ||
}; | ||
}); | ||
|
||
[it, describe].forEach((ob) => { | ||
ob.skip = function () { | ||
[ | ||
'describe.skip and it.skip are disabled,', | ||
'because they pollute the pipeline test output', | ||
// eslint-disable-next-line no-console | ||
].forEach(l => console.error(l)) | ||
throw new Error('do not use .skip()') | ||
}; | ||
}); |
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
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
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
Oops, something went wrong.