From 2ea299ef882ab459562ba85b5c72ef089f9be960 Mon Sep 17 00:00:00 2001 From: sam bland Date: Wed, 25 Nov 2026 20:13:27 +0000 Subject: [PATCH 1/2] Refactor build test Improved docs and separated code into functions --- node/build/build.test.js | 131 +++++++++++++++++++++++---------------- 1 file changed, 76 insertions(+), 55 deletions(-) diff --git a/node/build/build.test.js b/node/build/build.test.js index d601368a..9b5d5be7 100644 --- a/node/build/build.test.js +++ b/node/build/build.test.js @@ -18,66 +18,87 @@ import { fileURLToPath } from 'node:url' const nodeRoot = resolve(dirname(fileURLToPath(import.meta.url)), '..') const projectRoot = resolve(nodeRoot, '..') -describe('Django asset build', () => { - it('builds the complete asset set from the Node package without root npm tooling', () => { - const fixture = mkdtempSync(join(tmpdir(), 'direct asset build-')) +const expectedBuildFiles = [ + 'css/theme.css', + 'css/theme.css.map', + 'css/theme.min.css', + 'css/theme.min.css.map', + 'css/vendor.bundle.css', + 'js/main.js', + 'js/main.js.map', + 'js/main.min.js', + 'js/main.min.js.map', + 'js/vendor.bundle.js', + 'js/vendor.bundle.js.map', +] - try { - cpSync(nodeRoot, join(fixture, 'node'), { - recursive: true, - filter: (source) => - !['node_modules', 'storybook-static'].includes( - relative(nodeRoot, source).split(sep)[0] - ), - }) - cpSync(join(projectRoot, '.editorconfig'), join(fixture, '.editorconfig')) - symlinkSync( - join(nodeRoot, 'node_modules'), - join(fixture, 'node/node_modules'), - 'junction' - ) +function createBuildFixture() { + const fixture = mkdtempSync(join(tmpdir(), 'direct asset build-')) + + cpSync(nodeRoot, join(fixture, 'node'), { + recursive: true, + filter: (source) => + !['node_modules', 'storybook-static'].includes( + relative(nodeRoot, source).split(sep)[0] + ), + }) + cpSync(join(projectRoot, '.editorconfig'), join(fixture, '.editorconfig')) + symlinkSync( + join(nodeRoot, 'node_modules'), + join(fixture, 'node/node_modules'), + 'junction' + ) + + const assets = join(fixture, 'main/static/assets') + mkdirSync(join(assets, 'css'), { recursive: true }) + mkdirSync(join(assets, 'js'), { recursive: true }) + + return { fixture, assets } +} + +function runAssetBuild(fixture) { + execFileSync('npm', ['--prefix', join(fixture, 'node'), 'run', 'build'], { + cwd: fixture, + stdio: 'pipe', + timeout: 120000, + }) +} - const assets = join(fixture, 'main/static/assets') - mkdirSync(join(assets, 'css'), { recursive: true }) - mkdirSync(join(assets, 'js'), { recursive: true }) +function expectSourceMapSourcesToExist(assets, file) { + const map = JSON.parse(readFileSync(join(assets, file), 'utf8')) + expect(map.version).toBe(3) + expect(map.sources.length).toBeGreaterThan(0) - execFileSync('npm', ['--prefix', join(fixture, 'node'), 'run', 'build'], { - cwd: fixture, - stdio: 'pipe', - timeout: 120000, - }) + for (const source of map.sources) { + const sourcePath = source.startsWith('file:') + ? fileURLToPath(source) + : resolve(dirname(join(assets, file)), source) + expect(existsSync(sourcePath), source).toBe(true) + } +} - const files = readdirSync(assets, { recursive: true }).filter((file) => - /\.(css|js|map)$/.test(file) - ) - expect(files.sort()).toEqual([ - 'css/theme.css', - 'css/theme.css.map', - 'css/theme.min.css', - 'css/theme.min.css.map', - 'css/vendor.bundle.css', - 'js/main.js', - 'js/main.js.map', - 'js/main.min.js', - 'js/main.min.js.map', - 'js/vendor.bundle.js', - 'js/vendor.bundle.js.map', - ]) +function expectBuildOutputs(assets) { + const files = readdirSync(assets, { recursive: true }).filter((file) => + /\.(css|js|map)$/.test(file) + ) + expect(files.sort()).toEqual(expectedBuildFiles) - for (const file of files) { - expect(readFileSync(join(assets, file)).length).toBeGreaterThan(0) - if (file.endsWith('.map')) { - const map = JSON.parse(readFileSync(join(assets, file), 'utf8')) - expect(map.version).toBe(3) - expect(map.sources.length).toBeGreaterThan(0) - for (const source of map.sources) { - const sourcePath = source.startsWith('file:') - ? fileURLToPath(source) - : resolve(dirname(join(assets, file)), source) - expect(existsSync(sourcePath), source).toBe(true) - } - } - } + for (const file of files) { + expect(readFileSync(join(assets, file)).length).toBeGreaterThan(0) + if (file.endsWith('.map')) { + expectSourceMapSourcesToExist(assets, file) + } + } +} + +describe('Django asset build', () => { + it('builds the complete asset set from the Node package without root npm tooling', () => { + // Keep the build isolated from the repository's generated assets. + const { fixture, assets } = createBuildFixture() + + try { + runAssetBuild(fixture) + expectBuildOutputs(assets) } finally { rmSync(fixture, { recursive: true, force: true }) } From eafc8b428d65280487ba431fe035635052cd281d Mon Sep 17 00:00:00 2001 From: sam bland Date: Wed, 25 Nov 2026 20:13:35 +0000 Subject: [PATCH 2/2] Add node build to the node-ci.yml --- .github/workflows/node-ci.yml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/.github/workflows/node-ci.yml b/.github/workflows/node-ci.yml index fad800ac..130216b9 100644 --- a/.github/workflows/node-ci.yml +++ b/.github/workflows/node-ci.yml @@ -43,3 +43,19 @@ jobs: run: npm ci - name: Run lint run: npm run lint + run-build: + name: Run build + runs-on: ubuntu-latest + defaults: + run: + working-directory: node + steps: + - uses: actions/setup-node@v7 + with: + node-version: '26' + - name: Check out Git repository + uses: actions/checkout@v7 + - name: Install dependencies + run: npm ci + - name: Run build + run: npm run build