|
| 1 | +import test from "ava"; |
| 2 | +import sinonGlobal from "sinon"; |
| 3 | +import {fileURLToPath} from "node:url"; |
| 4 | +import ProjectGraph from "../../../lib/graph/ProjectGraph.js"; |
| 5 | +import ProjectBuilder from "../../../lib/build/ProjectBuilder.js"; |
| 6 | +import Application from "../../../lib/specifications/types/Application.js"; |
| 7 | +import * as taskRepository from "@ui5/builder/internal/taskRepository"; |
| 8 | + |
| 9 | +test.beforeEach((t) => { |
| 10 | + t.context.sinon = sinonGlobal.createSandbox(); |
| 11 | +}); |
| 12 | + |
| 13 | +test.afterEach.always((t) => { |
| 14 | + t.context.sinon.restore(); |
| 15 | + delete process.env.UI5_DATA_DIR; |
| 16 | +}); |
| 17 | + |
| 18 | +test.serial("Build application project twice without changes", async (t) => { |
| 19 | + const {sinon} = t.context; |
| 20 | + |
| 21 | + process.env.UI5_DATA_DIR = getTmpPath("application.a/.ui5"); |
| 22 | + |
| 23 | + async function createProjectBuilder() { |
| 24 | + const customApplicationProject = new Application(); |
| 25 | + await customApplicationProject.init({ |
| 26 | + "id": "application.a", |
| 27 | + "version": "1.0.0", |
| 28 | + "modulePath": getFixturePath("application.a"), |
| 29 | + "configuration": { |
| 30 | + "specVersion": "5.0", |
| 31 | + "type": "application", |
| 32 | + "metadata": { |
| 33 | + "name": "application.a" |
| 34 | + }, |
| 35 | + "kind": "project" |
| 36 | + } |
| 37 | + }); |
| 38 | + |
| 39 | + const graph = new ProjectGraph({ |
| 40 | + rootProjectName: customApplicationProject.getName(), |
| 41 | + }); |
| 42 | + graph.addProject(customApplicationProject); |
| 43 | + graph.seal(); // Graph needs to be sealed before building |
| 44 | + |
| 45 | + const buildConfig = {}; |
| 46 | + |
| 47 | + const projectBuilder = new ProjectBuilder({ |
| 48 | + graph, |
| 49 | + taskRepository, |
| 50 | + buildConfig |
| 51 | + }); |
| 52 | + sinon.spy(projectBuilder, "_buildProject"); |
| 53 | + return projectBuilder; |
| 54 | + } |
| 55 | + |
| 56 | + const destPath = getTmpPath("application.a/dist"); |
| 57 | + |
| 58 | + let projectBuilder = await createProjectBuilder(); |
| 59 | + |
| 60 | + // First build (with empty cache) |
| 61 | + await projectBuilder.build({destPath}); |
| 62 | + |
| 63 | + t.is(projectBuilder._buildProject.callCount, 1); |
| 64 | + t.is( |
| 65 | + projectBuilder._buildProject.getCall(0).args[0].getProject().getName(), |
| 66 | + "application.a", |
| 67 | + "application.a built in first build" |
| 68 | + ); |
| 69 | + |
| 70 | + // Second build (with cache, no changes) |
| 71 | + projectBuilder = await createProjectBuilder(); |
| 72 | + |
| 73 | + await projectBuilder.build({destPath}); |
| 74 | + |
| 75 | + t.is(projectBuilder._buildProject.callCount, 0, "No projects built in second build"); |
| 76 | +}); |
| 77 | + |
| 78 | +function getFixturePath(fixtureName) { |
| 79 | + return fileURLToPath(new URL(`../../fixtures/${fixtureName}`, import.meta.url)); |
| 80 | +} |
| 81 | + |
| 82 | +function getTmpPath(folderName) { |
| 83 | + return fileURLToPath(new URL(`../../tmp/${folderName}`, import.meta.url)); |
| 84 | +} |
0 commit comments