Skip to content

Commit c70c6a4

Browse files
committed
test
1 parent e2a1e6e commit c70c6a4

File tree

5 files changed

+73
-4
lines changed

5 files changed

+73
-4
lines changed

packages/@apphosting/adapter-angular/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"scripts": {
2424
"build": "rm -rf dist && tsc && chmod +x ./dist/bin/*",
2525
"test": "npm run test:unit && npm run test:functional",
26-
"test:unit": "ts-mocha -p tsconfig.json src/**/*.spec.ts",
26+
"test:unit": "ts-mocha -p tsconfig.json 'src/**/*.spec.ts' 'src/*.spec.ts'",
2727
"test:functional": "node --loader ts-node/esm ./e2e/run-local.ts",
2828
"localregistry:start": "npx verdaccio --config ../publish-dev/verdaccio-config.yaml",
2929
"localregistry:publish": "(npm view --registry=http://localhost:4873 @apphosting/adapter-angular && npm unpublish --@apphosting:registry=http://localhost:4873 --force); npm publish --@apphosting:registry=http://localhost:4873"

packages/@apphosting/adapter-angular/src/bin/build.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ metadata:
8383
const expectedOutputBundleOptions = {
8484
browserDirectory: "/browser",
8585
bundleYamlPath: resolve(".apphosting", "bundle.yaml"),
86+
outputDirectoryBasePath: resolve(".apphosting"),
8687
needsServerGenerated: false,
8788
serverFilePath: path.join("/server", "server.mjs"),
8889
};
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
const importUtils = import("@apphosting/adapter-angular/dist/utils.js");
2+
import assert from "assert";
3+
import fs from "fs";
4+
import { resolve } from "path";
5+
import path from "path";
6+
import { stringify as yamlStringify } from "yaml";
7+
import os from "os";
8+
9+
const { metaFrameworkOutputBundleExists } = await importUtils;
10+
11+
function generateTmpDir(): string {
12+
return fs.mkdtempSync(path.join(os.tmpdir(), "test-files"));
13+
}
14+
15+
describe("metaFrameworkOutputBundleExists", () => {
16+
let bundlePath: string;
17+
const originalCwd = process.cwd.bind(process);
18+
19+
beforeEach(() => {
20+
const tmpDir = generateTmpDir();
21+
process.cwd = () => tmpDir;
22+
fs.mkdirSync(resolve(tmpDir, ".apphosting"));
23+
bundlePath = resolve(tmpDir, ".apphosting", "bundle.yaml");
24+
});
25+
26+
afterEach(() => {
27+
process.cwd = originalCwd;
28+
});
29+
30+
it("unrecogznied bundle", async () => {
31+
const content = "chicken: bok bok";
32+
fs.writeFileSync(bundlePath, yamlStringify(content));
33+
assert(!metaFrameworkOutputBundleExists());
34+
});
35+
36+
it("no bundle exists", async () => {
37+
assert(!metaFrameworkOutputBundleExists());
38+
});
39+
40+
it("meta-framework bundle exists", async () => {
41+
const outputBundle: OutputBundleConfig = {
42+
version: "v1",
43+
runConfig: {
44+
runCommand: `does not matter`,
45+
},
46+
metadata: {
47+
framework: "nitro",
48+
},
49+
};
50+
fs.writeFileSync(bundlePath, yamlStringify(outputBundle));
51+
assert(metaFrameworkOutputBundleExists());
52+
});
53+
54+
it("angular bundle exists", async () => {
55+
const outputBundle: OutputBundleConfig = {
56+
version: "v1",
57+
58+
runConfig: {
59+
runCommand: `does not matter`,
60+
},
61+
metadata: {
62+
framework: "angular",
63+
},
64+
};
65+
fs.writeFileSync(bundlePath, yamlStringify(outputBundle));
66+
assert(!metaFrameworkOutputBundleExists());
67+
});
68+
});

packages/@apphosting/adapter-angular/src/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,8 +283,8 @@ export const metaFrameworkOutputBundleExists = () => {
283283
const bundleYamlPath = join(outputBundleDir, "bundle.yaml");
284284
if (existsSync(bundleYamlPath)) {
285285
try {
286-
const bundle: OutputBundleConfig = parseYaml(readFileSync(bundleYamlPath, "utf8"));
287-
if (bundle.metadata?.framework && bundle.metadata.framework !== "angular") {
286+
const bundle = parseYaml(readFileSync(bundleYamlPath, "utf8"));
287+
if (bundle?.metadata?.framework && bundle.metadata.framework !== "angular") {
288288
return true;
289289
}
290290
} catch (e) {

packages/@apphosting/adapter-angular/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"noEmit": false,
55
"outDir": "dist",
66
"rootDir": "src",
7-
"allowJs": true
7+
//"allowJs": true
88
},
99
"include": [
1010
"src/index.ts",

0 commit comments

Comments
 (0)