From aefb0498c36e629a87c8297cc1c3215870a6195c Mon Sep 17 00:00:00 2001 From: Arindam Bose Date: Thu, 12 Dec 2019 15:47:16 -0800 Subject: [PATCH] Un-hardcode test fixtures root path, and add operation handler for 'idle' event --- test/integration/lib/generate-fixture-json.js | 16 +++++++++------- test/integration/lib/operation-handlers.js | 10 ++++++++++ test/integration/testem.js | 11 ++++++----- 3 files changed, 25 insertions(+), 12 deletions(-) diff --git a/test/integration/lib/generate-fixture-json.js b/test/integration/lib/generate-fixture-json.js index c279593b5ad..b4bf77377ff 100644 --- a/test/integration/lib/generate-fixture-json.js +++ b/test/integration/lib/generate-fixture-json.js @@ -10,15 +10,16 @@ exports.generateFixtureJson = generateFixtureJson; exports.getAllFixtureGlobs = getAllFixtureGlobs; /** - * Analyzes the contents of the specified `directory` ,and inlines + * Analyzes the contents of the specified `path.join(rootDirectory, suiteDirectory)`, and inlines * the contents into a single json file which can then be imported and built into a bundle * to be shipped to the browser. * - * @param {string} directory + * @param {string} rootDirectory + * @param {string} suiteDirectory * @param {boolean} includeImages */ -function generateFixtureJson(directory, includeImages = false) { - const globs = getAllFixtureGlobs(directory); +function generateFixtureJson(rootDirectory, suiteDirectory, outputDirectory = 'test/integration/dist', includeImages = false) { + const globs = getAllFixtureGlobs(rootDirectory, suiteDirectory); const jsonPaths = globs[0]; const imagePaths = globs[1]; //Extract the filedata into a flat dictionary @@ -59,7 +60,7 @@ function generateFixtureJson(directory, includeImages = false) { // Re-nest by directory path, each directory path defines a testcase. const result = {}; for (const fullPath in allFiles) { - const testName = path.dirname(fullPath).replace('test/integration/', ''); + const testName = path.dirname(fullPath).replace(rootDirectory, ''); //Skip if test is malformed if (malformedTests[testName]) { continue; } @@ -73,7 +74,7 @@ function generateFixtureJson(directory, includeImages = false) { } const outputStr = JSON.stringify(result, null, 4); - const outputPath = path.join('test/integration/dist', OUTPUT_FILE); + const outputPath = path.join(outputDirectory, OUTPUT_FILE); return new Promise((resolve, reject) => { fs.writeFile(outputPath, outputStr, {encoding: 'utf8'}, (err) => { @@ -84,7 +85,8 @@ function generateFixtureJson(directory, includeImages = false) { }); } -function getAllFixtureGlobs(basePath) { +function getAllFixtureGlobs(rootDirectory, suiteDirectory) { + const basePath = path.join(rootDirectory, suiteDirectory); const jsonPaths = path.join(basePath, '/**/*.json'); const imagePaths = path.join(basePath, '/**/*.png'); diff --git a/test/integration/lib/operation-handlers.js b/test/integration/lib/operation-handlers.js index 0b85fdc2361..d653c892943 100644 --- a/test/integration/lib/operation-handlers.js +++ b/test/integration/lib/operation-handlers.js @@ -22,6 +22,16 @@ export const operationHandlers = { } }; wait(); + }, + idle(map, params, doneCb) { + const idle = function() { + if (!map.isMoving()) { + doneCb(); + } else { + map.once('render', idle); + } + }; + idle(); } }; diff --git a/test/integration/testem.js b/test/integration/testem.js index 09fe0135e9e..ec262ff7b0d 100644 --- a/test/integration/testem.js +++ b/test/integration/testem.js @@ -12,7 +12,8 @@ const notifier = require('node-notifier'); const rollupDevConfig = require('../../rollup.config').default; const rollupTestConfig = require('./rollup.config.test').default; -const fixturePath = 'test/integration/query-tests'; +const rootFixturePath = 'test/integration/'; +const suitePath = 'query-tests'; const fixtureBuildInterval = 2000; let beforeHookInvoked = false; @@ -79,7 +80,7 @@ module.exports = { // Retuns a promise that resolves when all artifacts are built function buildArtifactsCi() { //1. Compile fixture data into a json file, so it can be bundled - generateFixtureJson(fixturePath, {}); + generateFixtureJson(rootFixturePath, suitePath); //2. Build tape const tapePromise = buildTape(); //3. Build test artifacts in parallel @@ -94,15 +95,15 @@ function buildArtifactsDev() { return buildTape().then(() => { // A promise that resolves on the first build of fixtures.json return new Promise((resolve, reject) => { - fixtureWatcher = chokidar.watch(getAllFixtureGlobs(fixturePath)); + fixtureWatcher = chokidar.watch(getAllFixtureGlobs(rootFixturePath, suitePath)); let needsRebuild = false; fixtureWatcher.on('ready', () => { - generateFixtureJson(fixturePath); + generateFixtureJson(rootFixturePath, suitePath); //Throttle calls to `generateFixtureJson` to run every 2s setInterval(() => { if (needsRebuild) { - generateFixtureJson(fixturePath); + generateFixtureJson(rootFixturePath, suitePath); needsRebuild = false; } }, fixtureBuildInterval);