Files
Xen-Orchestra-xen-orchestra…/scripts/check-changed-pkgs.test.mjs
Mathieu 025f6eb533 feat(vectura): bump and build in the pull request, not at release (#10573)
The binary in git is now the build of its sources. build.sh keeps the paths
of the machine out of the binary and refuses another zig or cargo-zigbuild
version, and the Vectura workflow fails when its build differs from the
committed binary. The binary is rebuilt with this build.sh: only its paths
change, the version stays 0.1.2.

vectura is no longer released on its own. release.sh runs once at the end of
the pull request which changes vectura and no longer commits. bump-pkg,
gen-deps-list.js and check-changed-pkgs.js drop the vectura pseudo-package: a
change under vectura/ requires a release of @xen-orchestra/vmware-explorer,
which ships the committed binary as is. release.sh puts Cargo.toml and
Cargo.lock back when the build or the check of the binary fails.
2026-10-15 10:43:00 +02:00

132 lines
4.3 KiB
JavaScript

import assert from 'node:assert/strict'
import { describe, it } from 'node:test'
import { getChangedPackages, isIgnoredFile } from './check-changed-pkgs.js'
const PACKAGE_NAMES_BY_DIR = new Map([
['@vates/types', '@vates/types'],
['@xen-orchestra/babel-config', '@xen-orchestra/babel-config'],
['@xen-orchestra/backups', '@xen-orchestra/backups'],
['@xen-orchestra/lite', '@xen-orchestra/lite'],
['@xen-orchestra/vmware-explorer', '@xen-orchestra/vmware-explorer'],
['packages/xo-server', 'xo-server'],
])
const changedPackages = changedFiles => getChangedPackages(changedFiles, PACKAGE_NAMES_BY_DIR)
const changedPackageNames = changedFiles => Array.from(changedPackages(changedFiles).keys()).sort()
describe('isIgnoredFile', function () {
for (const file of [
'@vates/nbd-client/tests/ca-cert.pem',
// a test file which does not follow the `*.test.*` naming
'@vates/xml/test/parse.js',
'@xen-orchestra/backups/_runners/_vmRunners/__snapshots__/IncrementalXapi.mjs.snap',
'@xen-orchestra/backups/RemoteAdapter.integ.mjs',
'@xen-orchestra/backups/RemoteAdapter.test.mjs',
'@xen-orchestra/backups/docs/design.md',
'@xen-orchestra/backups/README.md',
'@xen-orchestra/web-core/src/composables/foo.spec.ts',
// a test directory nested in the package sources
'@xen-orchestra/web/src/test/create-vm.ts',
'packages/xo-cli/.USAGE.md',
'packages/xo-server/.npmignore',
'packages/xo-server/perf.load.mjs',
'packages/xo-web/src/common/index.spec.js',
]) {
it(`ignores ${file}`, function () {
assert.equal(isIgnoredFile(file), true)
})
}
for (const file of [
'@vates/types/index.mts',
'@xen-orchestra/backups/RemoteAdapter.mjs',
'@xen-orchestra/backups/package.json',
// not a test file, only a file *about* tests
'@xen-orchestra/backups/testUtils.mjs',
// `docs` and `test` as file names, not as directories
'packages/xo-server/docs.md',
'packages/xo-server/test.mjs',
'packages/xo-web/src/common/index.js',
]) {
it(`does not ignore ${file}`, function () {
assert.equal(isIgnoredFile(file), false)
})
}
})
describe('getChangedPackages', function () {
it('maps a file to the package which owns its directory', function () {
assert.deepEqual(changedPackageNames(['packages/xo-server/src/api/vm.mjs', '@vates/types/index.mts']), [
'@vates/types',
'xo-server',
])
})
it('reports the files which require the release of each package', function () {
assert.deepEqual(
Object.fromEntries(
changedPackages([
'packages/xo-server/src/api/vm.mjs',
'packages/xo-server/src/api/vm.spec.mjs',
'packages/xo-server/package.json',
])
),
{ 'xo-server': ['packages/xo-server/src/api/vm.mjs', 'packages/xo-server/package.json'] }
)
})
it('ignores files which are not in a package', function () {
assert.deepEqual(
changedPackageNames([
'CHANGELOG.unreleased.md',
'.github/workflows/ci.yml',
'scripts/check-changed-pkgs.js',
'docs/backups.md',
'packages/not-a-package/index.js',
]),
[]
)
})
it('ignores files directly in a package scope directory', function () {
assert.deepEqual(changedPackageNames(['@vates/README.md', 'packages/tsconfig.json']), [])
})
it('ignores packages which are never listed in the changelog', function () {
assert.deepEqual(
changedPackageNames([
'@xen-orchestra/babel-config/index.js',
'@xen-orchestra/lite/src/App.vue',
'@vates/types/index.mts',
]),
['@vates/types']
)
})
it('ignores a package whose changes are limited to ignored files', function () {
assert.deepEqual(
changedPackageNames([
'@xen-orchestra/backups/README.md',
'@xen-orchestra/backups/tests/fixture.json',
'@vates/types/types.test.mts',
]),
[]
)
})
it('maps a vectura file to the package which bundles its binary', function () {
assert.deepEqual(
changedPackageNames([
'@xen-orchestra/vmware-explorer/vectura/src/main.rs',
'@xen-orchestra/vmware-explorer/vectura/tests/cli.rs',
]),
['@xen-orchestra/vmware-explorer']
)
})
it('handles an empty list of changed files', function () {
assert.deepEqual(changedPackageNames([]), [])
})
})