Skip to content

Commit

Permalink
Test: Copy scanner fixtures instead of managing a layer
Browse files Browse the repository at this point in the history
This optimization will cut down parsing time and reuse the cache.
  • Loading branch information
deribaucourt committed May 31, 2024
1 parent f3674b7 commit 5ad1bf6
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 23 deletions.
27 changes: 18 additions & 9 deletions client/src/__tests__/unit-tests/driver/scanner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
* ------------------------------------------------------------------------------------------ */

import path from 'path'
import fs from 'fs'
import { BitBakeProjectScanner } from '../../../driver/BitBakeProjectScanner'
import { BitbakeDriver } from '../../../driver/BitbakeDriver'
import { BITBAKE_TIMEOUT } from '../../../utils/ProcessUtils'
import { mockVscodeEvents } from '../../utils/vscodeMock'
import { addLayer, removeLayer } from '../../utils/bitbake'
import { importRecipe, removeRecipe } from '../../utils/bitbake'
import { logger } from '../../../lib/src/utils/OutputLogger'

let bitBakeProjectScanner: BitBakeProjectScanner
Expand Down Expand Up @@ -39,23 +40,31 @@ describe('BitBakeProjectScanner', () => {
})
mockVscodeEvents()
bitBakeProjectScanner.bitbakeDriver.spawnBitbakeProcess('devtool modify busybox').then((child) => {
child.onExit((event) => {
child.onExit(async (event) => {
expect(event.exitCode).toBe(0)
addLayer(
path.resolve(__dirname, '../../../../../integration-tests/project-folder/sources/meta-fixtures-versions'),
path.resolve(__dirname, '../../../../../integration-tests/project-folder/build'))
void bitBakeProjectScanner.rescanProject()
const pokyPath = path.resolve(__dirname, '../../../../../integration-tests/project-folder/sources/poky')
const fixtureVersionPath = path.resolve(__dirname, '../../../../../integration-tests/project-folder/sources/meta-fixtures-versions/recipes-fixtures/fixture-version')
const recipes = fs.readdirSync(fixtureVersionPath)
for (const recipe of recipes) {
await importRecipe(path.join(fixtureVersionPath, recipe), pokyPath)
}
const localConfPath = path.join(pathToBuildFolder, 'conf', 'local.conf')
fs.appendFileSync(localConfPath, 'PREFERRED_VERSION_fixture-version = "0.2.0"\n')
await bitBakeProjectScanner.rescanProject()
})
}, (error) => {
throw error
})
}, BITBAKE_TIMEOUT)

afterAll((done) => {
removeLayer(
path.resolve(__dirname, '../../../../../integration-tests/project-folder/sources/meta-fixtures-versions'),
path.resolve(__dirname, '../../../../../integration-tests/project-folder/build'))
bitBakeProjectScanner.bitbakeDriver.spawnBitbakeProcess('devtool reset busybox').then((child) => {
const pokyPath = path.resolve(__dirname, '../../../../../integration-tests/project-folder/sources/poky')
const fixtureVersionPath = path.resolve(__dirname, '../../../../../integration-tests/project-folder/sources/meta-fixtures-versions/recipes-fixtures/fixture-version')
const recipes = fs.readdirSync(fixtureVersionPath)
for (const recipe of recipes) {
void removeRecipe(path.join(fixtureVersionPath, recipe), pokyPath)
}
child.onExit(() => {
done()
})
Expand Down
21 changes: 7 additions & 14 deletions client/src/__tests__/utils/bitbake.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,13 @@
import path from 'path'
import fs from 'fs'

// This is similar to the integration-tests addLayer() but doesn't use the VSCode API
export function addLayer (layer: string, buildFolder: string): void {
const bblayersConf = path.resolve(buildFolder, 'conf/bblayers.conf')
const bblayersConfContent = fs.readFileSync(bblayersConf)
let fileContent = bblayersConfContent.toString()
fileContent += `\nBBLAYERS+="${layer}"\n`
fs.writeFileSync(bblayersConf, fileContent)
/// Copy a recipe into poky
export async function importRecipe (recipePath: string, pokyPath: string): Promise<void> {
const pokyDestinationPath = path.resolve(pokyPath, 'meta/recipes-core/base-files', path.basename(recipePath))
await fs.promises.copyFile(recipePath, pokyDestinationPath)
}

// This is similar to the integration-tests removeLayer() but doesn't use the VSCode API
export function removeLayer (layer: string, buildFolder: string): void {
const bblayersConf = path.resolve(buildFolder, 'conf/bblayers.conf')
const bblayersConfContent = fs.readFileSync(bblayersConf)
let fileContent = bblayersConfContent.toString()
fileContent = fileContent.replace(`\nBBLAYERS+="${layer}"`, '')
fs.writeFileSync(bblayersConf, fileContent)
export async function removeRecipe (recipePath: string, pokyPath: string): Promise<void> {
const pokyDestinationPath = path.resolve(pokyPath, 'meta/recipes-core/base-files', path.basename(recipePath))
await fs.promises.unlink(pokyDestinationPath)
}

0 comments on commit 5ad1bf6

Please sign in to comment.