Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Un-hardcode test fixtures root path for fixture builder #9105

Merged
merged 1 commit into from
Dec 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions test/integration/lib/generate-fixture-json.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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; }

Expand All @@ -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) => {
Expand All @@ -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');

Expand Down
10 changes: 10 additions & 0 deletions test/integration/lib/operation-handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
};

Expand Down
11 changes: 6 additions & 5 deletions test/integration/testem.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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);
Expand Down