Skip to content

Commit

Permalink
Fix build tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cezaraugusto committed Aug 20, 2024
1 parent 59c5118 commit 2faa773
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 21 deletions.
3 changes: 2 additions & 1 deletion examples/data.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { DevOptions } from 'extension-develop'
import {type Template} from './types'

const DEFAULT_TEMPLATE: Template = {
Expand Down Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions install_scripts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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/"
70 changes: 53 additions & 17 deletions programs/develop/__spec__/build.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)(
Expand All @@ -52,8 +84,6 @@ describe('extension build', () => {
template.name
)

console.log({templatePath})

await extensionBuild(templatePath, {
browser: SUPPORTED_BROWSERS[0] as 'chrome'
})
Expand Down Expand Up @@ -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()
})
)
},
Expand All @@ -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
)
Expand All @@ -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
)
Expand All @@ -149,15 +194,6 @@ describe('extension build', () => {
'examples',
template.name
)
const outputPath = path.join(
__dirname,
'..',
'..',
'..',
'examples',
template.name,
'dist'
)

await extensionBuild(templatePath, {
zip: true,
Expand All @@ -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()
},
Expand Down

0 comments on commit 2faa773

Please sign in to comment.