-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
96 additions
and
6 deletions.
There are no files selected for viewing
92 changes: 92 additions & 0 deletions
92
packages/@apphosting/adapter-angular/src/bin/build.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
const importUtils = import("@apphosting/adapter-angular/dist/utils.js"); | ||
import assert from "assert"; | ||
import { resolve } from "path"; | ||
import fs from "fs"; | ||
import path from "path"; | ||
import os from "os"; | ||
import { OutputPathOptions } from "../interface.js"; | ||
|
||
describe("build commands", () => { | ||
let tmpDir: string; | ||
let outputPathOptions: OutputPathOptions; | ||
beforeEach(() => { | ||
tmpDir = generateTmpDir(); | ||
outputPathOptions = { | ||
baseDirectory: resolve(tmpDir, "dist", "test"), | ||
browserDirectory: resolve(tmpDir, ".apphosting", "dist", "browser"), | ||
bundleYamlPath: resolve(tmpDir, ".apphosting", "bundle.yaml"), | ||
outputBaseDirectory: resolve(tmpDir, ".apphosting", "dist"), | ||
outputDirectory: resolve(tmpDir, ".apphosting"), | ||
serverFilePath: resolve(tmpDir, ".apphosting", "dist", "server", "server.mjs"), | ||
}; | ||
}); | ||
|
||
it("expects all output bundle files to be generated", async () => { | ||
const { generateOutputDirectory } = await importUtils; | ||
const files = { | ||
"dist/test/browser/browserfile": "", | ||
"dist/test/server/server.mjs": "", | ||
}; | ||
generateTestFiles(tmpDir, files); | ||
await generateOutputDirectory(tmpDir, outputPathOptions); | ||
|
||
const expectedFiles = { | ||
".apphosting/dist/browser/browserfile": "", | ||
".apphosting/dist/server/server.mjs": "", | ||
".apphosting/bundle.yaml": `headers: [] | ||
redirects: [] | ||
rewrites: [] | ||
runCommand: node .apphosting/dist/server/server.mjs | ||
neededDirs: | ||
- .apphosting | ||
staticAssets: | ||
- .apphosting/dist/browser | ||
`, | ||
}; | ||
validateTestFiles(tmpDir, expectedFiles); | ||
}); | ||
|
||
it("test populate output bundle options", async () => { | ||
const { populateOutputBundleOptions } = await importUtils; | ||
const expectedOutputBundleOptions = { | ||
baseDirectory: "/test", | ||
browserDirectory: resolve(".apphosting", "browser"), | ||
bundleYamlPath: resolve(".apphosting", "bundle.yaml"), | ||
outputBaseDirectory: resolve(".apphosting", "dist"), | ||
outputDirectory: resolve("", ".apphosting"), | ||
serverFilePath: resolve(".apphosting", "server", "server.mjs"), | ||
}; | ||
const outputPaths = { | ||
root: new URL("file:///test"), | ||
server: new URL("file:///server"), | ||
browser: new URL("file:///browser"), | ||
}; | ||
assert.deepEqual(populateOutputBundleOptions(outputPaths), expectedOutputBundleOptions); | ||
}); | ||
afterEach(() => { | ||
fs.rmSync(tmpDir, { recursive: true, force: true }); | ||
}); | ||
}); | ||
function generateTmpDir(): string { | ||
return fs.mkdtempSync(path.join(os.tmpdir(), "test-files")); | ||
} | ||
|
||
function generateTestFiles(baseDir: string, filesToGenerate: Object): void { | ||
Object.entries(filesToGenerate).forEach((file) => { | ||
const fileName = file[0]; | ||
const contents = file[1]; | ||
const fileToGenerate = path.join(baseDir, fileName); | ||
fs.mkdirSync(path.dirname(fileToGenerate), { recursive: true }); | ||
fs.writeFileSync(fileToGenerate, contents); | ||
}); | ||
} | ||
|
||
function validateTestFiles(baseDir: string, expectedFiles: Object): void { | ||
Object.entries(expectedFiles).forEach((file) => { | ||
const fileName = file[0]; | ||
const expectedContents = file[1]; | ||
const fileToRead = path.join(baseDir, fileName); | ||
const contents = fs.readFileSync(fileToRead).toString(); | ||
assert.deepEqual(contents, expectedContents); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters