From 2faa773f884a273df6ba6e2f49cbdc785cdc1e15 Mon Sep 17 00:00:00 2001 From: Cezar Augusto Date: Mon, 19 Aug 2024 23:01:58 -0300 Subject: [PATCH] Fix build tests --- examples/data.ts | 3 +- install_scripts.sh | 6 +-- programs/develop/__spec__/build.spec.ts | 70 +++++++++++++++++++------ 3 files changed, 58 insertions(+), 21 deletions(-) diff --git a/examples/data.ts b/examples/data.ts index bd4ee90f..58cbf7cf 100644 --- a/examples/data.ts +++ b/examples/data.ts @@ -1,3 +1,4 @@ +import { DevOptions } from 'extension-develop' import {type Template} from './types' const DEFAULT_TEMPLATE: Template = { @@ -316,7 +317,7 @@ const ALL_TEMPLATES_BUT_DEFAULT = ALL_TEMPLATES.filter( (template) => template.name !== 'init' ) -const SUPPORTED_BROWSERS = ['chrome', 'edge', 'firefox'] +const SUPPORTED_BROWSERS: DevOptions['browser'][] = ['chrome', 'edge', 'firefox'] export { SUPPORTED_BROWSERS, diff --git a/install_scripts.sh b/install_scripts.sh index e0d0eadc..8837c47a 100644 --- a/install_scripts.sh +++ b/install_scripts.sh @@ -5,10 +5,10 @@ for dir in ./examples/*/ ; do if [ -d "$dir" ]; then echo "Entering directory: $dir" cd "$dir" - echo "Running npm install in $dir" - npm install + echo "Running yarn in $dir" + yarn cd - > /dev/null fi done -echo "npm install completed in all top-level folders within ./examples/" +echo "yarn completed in all top-level folders within ./examples/" diff --git a/programs/develop/__spec__/build.spec.ts b/programs/develop/__spec__/build.spec.ts index 15a55feb..377a1f90 100644 --- a/programs/develop/__spec__/build.spec.ts +++ b/programs/develop/__spec__/build.spec.ts @@ -7,6 +7,33 @@ import { } from '../../../examples/data' import {removeAllTemplateDistFolders} from './helpers' import {extensionBuild} from '../dist/module' +import {exec} from 'child_process' + +function runYarnInTopLevelFolders(templatePath: string): void { + // Read the contents of the templatePath directory + const folders = fs + .readdirSync(templatePath, {withFileTypes: true}) + .filter((dirent) => dirent.isDirectory()) // Filter only directories + .map((dirent) => dirent.name) // Map to the directory names + + folders.forEach((folder) => { + const folderPath = path.join(templatePath, folder) + + console.log(`Running yarn in ${folderPath}...`) + + // Run the yarn command in each top-level folder + exec('yarn', {cwd: folderPath}, (error, stdout, stderr) => { + if (error) { + console.error(`Error running yarn in ${folderPath}:`, error) + return + } + if (stderr) { + console.error(`Yarn stderr in ${folderPath}:`, stderr) + } + console.log(`Yarn output in ${folderPath}:\n${stdout}`) + }) + }) +} function distFileExists( templateName: string, @@ -35,9 +62,14 @@ function distFileExists( } describe('extension build', () => { + beforeAll(() => { + // Run yarn in all top-level folders of the examples directory + // runYarnInTopLevelFolders(path.join(__dirname, '..', '..', '..', 'examples')) + }) + beforeEach(async () => { await removeAllTemplateDistFolders() - }) + }, 30000) describe('running built-in templates', () => { it.each(ALL_TEMPLATES)( @@ -52,8 +84,6 @@ describe('extension build', () => { template.name ) - console.log({templatePath}) - await extensionBuild(templatePath, { browser: SUPPORTED_BROWSERS[0] as 'chrome' }) @@ -83,9 +113,11 @@ describe('extension build', () => { // Running browsers in parallel by invoking them sequentially await Promise.all( - SUPPORTED_BROWSERS.map(async (browser) => { - await extensionBuild(templatePath, {browser: browser as 'chrome'}) - expect(distFileExists(template.name, browser)).toBeTruthy() + SUPPORTED_BROWSERS.filter(browser => browser !== 'chrome').map(async (browser) => { + await extensionBuild(templatePath, {browser: browser as any}) + expect( + path.join(templatePath, SUPPORTED_BROWSERS[0], 'manifest.json') + ).toBeTruthy() }) ) }, @@ -110,6 +142,10 @@ describe('extension build', () => { browser: SUPPORTED_BROWSERS[0] as 'chrome', polyfill: true }) + + expect( + path.join(templatePath, SUPPORTED_BROWSERS[0], 'manifest.json') + ).toBeTruthy() }, 80000 ) @@ -133,7 +169,16 @@ describe('extension build', () => { zip: true }) - expect(distFileExists(template.name, 'chrome')).toBeTruthy() + expect( + fs.existsSync( + path.join( + templatePath, + 'dist', + SUPPORTED_BROWSERS[0], + `${template.name}-0.0.1.zip` + ) + ) + ).toBeTruthy() }, 80000 ) @@ -149,15 +194,6 @@ describe('extension build', () => { 'examples', template.name ) - const outputPath = path.join( - __dirname, - '..', - '..', - '..', - 'examples', - template.name, - 'dist' - ) await extensionBuild(templatePath, { zip: true, @@ -167,7 +203,7 @@ describe('extension build', () => { expect( fs.existsSync( - path.join(outputPath, `${template.name}-0.0.1-source.zip`) + path.join(templatePath, 'dist', `${template.name}-0.0.1-source.zip`) ) ).toBeTruthy() },