Skip to content

fix(build): build/test on windows #6431

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

Merged
merged 6 commits into from
Oct 27, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fix: Modified based on review suggestions.
* Change generator test output directory.
* Formatting test output as previously.
  • Loading branch information
yamadayutaka committed Oct 7, 2022
commit 4405364cb473b83b5a5da3db9c3cb771f33d82e2
17 changes: 6 additions & 11 deletions scripts/gulpfiles/build_tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@ const NAMESPACE_PROPERTY = '__namespace__';
const chunks = [
{
name: 'blockly',
entry: path.join(CORE_DIR, 'main.js'),
entry: posixPath((argv.compileTs) ?
path.join(TSC_OUTPUT_DIR, CORE_DIR, 'main.js') :
path.join(CORE_DIR, 'main.js')),
Comment on lines +107 to +109
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It appears that you are trying to helpfully merge in code from getChunkOptions that I should have deleted that code in PR #6220. Ooops! Since it obviously hasn't been causing any problems until now I'm not going to block this PR because of my own mistake.

I believe that if I had removed that code as I intended to then the you would have written this instead, and I will apply this fix in another PR I am preparing that touches all of this again anyway:

Suggested change
entry: posixPath((argv.compileTs) ?
path.join(TSC_OUTPUT_DIR, CORE_DIR, 'main.js') :
path.join(CORE_DIR, 'main.js')),
entry: posixPath(path.join(CORE_DIR, 'main.js')),

exports: 'module$build$src$core$blockly',
reexport: 'Blockly',
},
Expand Down Expand Up @@ -364,7 +366,6 @@ function buildDeps(done) {
const args = roots.map(root => `--root '${root}' `).join('');
exec(
`closure-make-deps ${args}`,
{stdio: ['inherit', 'inherit', 'pipe']},
(error, stdout, stderr) => {
console.warn(filterErrors(stderr));
if (error) {
Expand All @@ -380,7 +381,6 @@ function buildDeps(done) {
testRoots.map(root => `--root '${root}' `).join('');
exec(
`closure-make-deps ${testArgs}`,
{stdio: ['inherit', 'inherit', 'pipe']},
(error, stdout, stderr) => {
console.warn(filterErrors(stderr));
if (error) {
Expand Down Expand Up @@ -536,11 +536,6 @@ return ${chunk.exports};
* closure-calculate-chunks.
*/
function getChunkOptions() {
if (argv.compileTs) {
chunks[0].entry = path.join(TSC_OUTPUT_DIR, chunks[0].entry);
}
Comment on lines -523 to -525
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I should have deleted this bit a long time ago.

// Convert chunk entry path to posix.
chunks.forEach(chunk => chunk.entry = posixPath(chunk.entry));
const basePath =
path.join(TSC_OUTPUT_DIR, 'closure', 'goog', 'base_minimal.js');
const cccArgs = [
Expand Down Expand Up @@ -578,9 +573,9 @@ function getChunkOptions() {
// chunk depends on any chunk but the first), so we look for
// one of the entrypoints amongst the files in each chunk.
const chunkByNickname = Object.create(null);
// Convert js file path to posix.
const jsFiles = rawOptions.js.slice()
.map(p => posixPath(p)); // Will be modified via .splice!
// Copy and convert to posix js file paths.
// Result will be modified via `.splice`!
const jsFiles = rawOptions.js.map(p => posixPath(p));
const chunkList = rawOptions.chunk.map((element) => {
const [nickname, numJsFiles, parentNick] = element.split(':');

Expand Down
41 changes: 21 additions & 20 deletions scripts/gulpfiles/test_tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const {BUILD_DIR} = require('./config');
const runGeneratorsInBrowser =
require('../../tests/generators/run_generators_in_browser.js');

const TMP_DIR = 'tests/generators/tmp/';
const OUTPUT_DIR = 'build/generators/';
const GOLDEN_DIR = 'tests/generators/golden/';

const BOLD_GREEN = '\x1b[1;32m';
Expand All @@ -34,18 +34,23 @@ let failerCount = 0;
* Helper method for running test code block.
* @param {string} id test id
* @param {function} block test code block
* @param {boolean} grouping grouping log lines (for GitHub Action)
* @return {Promise} asynchronous result
*/
function runTestBlock(id, block) {
function runTestBlock(id, block, grouping = true) {
return new Promise((resolve) => {
console.log('=======================================');
console.log(`== ${id}`);
if (process.env.CI && grouping) console.log('::group::');
block()
.then((result) => {
if (process.env.CI && grouping) console.log('::endgroup::');
console.log(`${BOLD_GREEN}SUCCESS:${ANSI_RESET} ${id}`);
resolve(result);
})
.catch((err) => {
if (process.env.CI && grouping) console.log('::endgroup::');
console.log(`${BOLD_GREEN}SUCCESS:${ANSI_RESET} ${id}`);
failerCount++;
console.error(err.message);
console.log(`${BOLD_RED}FAILED:${ANSI_RESET} ${id}`);
Expand All @@ -64,7 +69,7 @@ function runTestBlock(id, block) {
function runTestCommand(id, command) {
return runTestBlock(id, async() => {
return execSync(command, {stdio: 'inherit'});
});
}, false);
}

/**
Expand Down Expand Up @@ -219,28 +224,28 @@ function compareFile(file1, file2) {
*/
function checkResult(suffix) {
const fileName = `generated.${suffix}`;
const tmpFileName = path.posix.join(TMP_DIR, fileName);
const resultFileName = path.posix.join(OUTPUT_DIR, fileName);

const SUCCESS_PREFIX = `${BOLD_GREEN}SUCCESS:${ANSI_RESET}`;
const FAILURE_PREFIX = `${BOLD_RED}FAILED:${ANSI_RESET}`;

if (fs.existsSync(tmpFileName)) {
if (fs.existsSync(resultFileName)) {
const goldenFileName = path.posix.join(GOLDEN_DIR, fileName);
if (fs.existsSync(goldenFileName)) {
if (compareFile(tmpFileName, goldenFileName)) {
if (compareFile(resultFileName, goldenFileName)) {
console.log(`${SUCCESS_PREFIX} ${suffix}: ` +
`${tmpFileName} matches ${goldenFileName}`);
`${resultFileName} matches ${goldenFileName}`);
return 0;
} else {
console.log(
`${FAILURE_PREFIX} ${suffix}: ` +
`${tmpFileName} does not match ${goldenFileName}`);
`${resultFileName} does not match ${goldenFileName}`);
}
} else {
console.log(`File ${goldenFileName} not found!`);
}
} else {
console.log(`File ${tmpFileName} not found!`);
console.log(`File ${resultFileName} not found!`);
}
return 1;
}
Expand All @@ -252,20 +257,17 @@ function checkResult(suffix) {
function generators() {
return runTestBlock('generators', async() => {
// Clean up.
rimraf.sync(TMP_DIR);
fs.mkdirSync(TMP_DIR);
rimraf.sync(OUTPUT_DIR);
fs.mkdirSync(OUTPUT_DIR);

await runGeneratorsInBrowser().catch(() => {});
await runGeneratorsInBrowser(OUTPUT_DIR).catch(() => {});

const generatorSuffixes = ['js', 'py', 'dart', 'lua', 'php'];
let failed = 0;
generatorSuffixes.forEach((suffix) => {
failed += checkResult(suffix);
});

// Clean up.
rimraf.sync(TMP_DIR);

if (failed === 0) {
console.log(`${BOLD_GREEN}All generator tests passed.${ANSI_RESET}`);
} else {
Expand Down Expand Up @@ -316,7 +318,7 @@ function reportTestResult() {
}

// Indivisual tasks.
const testTasks = {
const testTasks = [
eslint,
buildDebug,
renamings,
Expand All @@ -327,13 +329,12 @@ const testTasks = {
node,
advancedCompile,
reportTestResult,
};
];

// Run all tests in sequence.
const test = gulp.series(Object.values(testTasks));
const test = gulp.series(...testTasks);

module.exports = {
test,
// Export indivisual tasks.
...testTasks,
generators,
};
8 changes: 5 additions & 3 deletions tests/generators/run_generators_in_browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*/
var webdriverio = require('webdriverio');
var fs = require('fs');
var path = require('path');

module.exports = runGeneratorsInBrowser;

Expand All @@ -35,9 +36,10 @@ async function runLangGeneratorInBrowser(browser, filename, codegenFn) {
* Runs the generator tests in Chrome. It uses webdriverio to
* launch Chrome and load index.html. Outputs a summary of the test results
* to the console and outputs files for later validation.
* @param {string} outputDir output directory
* @return the Thenable managing the processing of the browser tests.
*/
async function runGeneratorsInBrowser() {
async function runGeneratorsInBrowser(outputDir) {
var options = {
capabilities: {
browserName: 'chrome',
Expand All @@ -60,7 +62,7 @@ async function runGeneratorsInBrowser() {
}

var url = 'file://' + __dirname + '/index.html';
var prefix = 'tests/generators/tmp/generated';
var prefix = path.join(outputDir, 'generated');

console.log('Starting webdriverio...');
const browser = await webdriverio.remote(options);
Expand Down Expand Up @@ -97,7 +99,7 @@ async function runGeneratorsInBrowser() {
}

if (require.main === module) {
runGeneratorsInBrowser().catch(e => {
runGeneratorsInBrowser('tests/generators/tmp').catch(e => {
console.error(e);
process.exit(1);
}).then(function(result) {
Expand Down