@superblocksteam/sdk 2.0.6 → 2.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/application-build.mjs +6 -2
- package/dist/application-build.mjs.map +1 -1
- package/dist/cli-replacement/automatic-upgrades.d.ts +5 -2
- package/dist/cli-replacement/automatic-upgrades.d.ts.map +1 -1
- package/dist/cli-replacement/automatic-upgrades.js +221 -93
- package/dist/cli-replacement/automatic-upgrades.js.map +1 -1
- package/dist/cli-replacement/dev.d.mts +1 -2
- package/dist/cli-replacement/dev.d.mts.map +1 -1
- package/dist/cli-replacement/dev.mjs +57 -32
- package/dist/cli-replacement/dev.mjs.map +1 -1
- package/dist/client.d.ts +34 -0
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +92 -1
- package/dist/client.js.map +1 -1
- package/dist/dev-utils/dev-logger.d.mts +17 -7
- package/dist/dev-utils/dev-logger.d.mts.map +1 -1
- package/dist/dev-utils/dev-logger.mjs +50 -9
- package/dist/dev-utils/dev-logger.mjs.map +1 -1
- package/dist/dev-utils/dev-server.d.mts.map +1 -1
- package/dist/dev-utils/dev-server.mjs +8 -12
- package/dist/dev-utils/dev-server.mjs.map +1 -1
- package/dist/dev-utils/dev-tracer.d.ts +2 -0
- package/dist/dev-utils/dev-tracer.d.ts.map +1 -1
- package/dist/dev-utils/dev-tracer.js +42 -35
- package/dist/dev-utils/dev-tracer.js.map +1 -1
- package/dist/dev-utils/vite-plugin-build-manifest-stub.d.mts +10 -0
- package/dist/dev-utils/vite-plugin-build-manifest-stub.d.mts.map +1 -0
- package/dist/dev-utils/vite-plugin-build-manifest-stub.mjs +27 -0
- package/dist/dev-utils/vite-plugin-build-manifest-stub.mjs.map +1 -0
- package/dist/dev-utils/vite-plugin-sb-cdn.d.mts.map +1 -1
- package/dist/dev-utils/vite-plugin-sb-cdn.mjs +13 -3
- package/dist/dev-utils/vite-plugin-sb-cdn.mjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/vite-plugin-generate-build-manifest.d.mts +21 -0
- package/dist/vite-plugin-generate-build-manifest.d.mts.map +1 -0
- package/dist/vite-plugin-generate-build-manifest.mjs +130 -0
- package/dist/vite-plugin-generate-build-manifest.mjs.map +1 -0
- package/dist/vite-plugin-inject-sb-ids-transform.mjs +1 -1
- package/dist/vite-plugin-inject-sb-ids-transform.mjs.map +1 -1
- package/package.json +6 -4
- package/src/application-build.mts +6 -3
- package/src/cli-replacement/automatic-upgrades.ts +278 -113
- package/src/cli-replacement/dev.mts +77 -43
- package/src/client.ts +115 -0
- package/src/dev-utils/dev-logger.mts +94 -20
- package/src/dev-utils/dev-server.mts +10 -12
- package/src/dev-utils/dev-tracer.ts +48 -37
- package/src/dev-utils/vite-plugin-build-manifest-stub.mts +30 -0
- package/src/dev-utils/vite-plugin-sb-cdn.mts +14 -3
- package/src/index.ts +4 -0
- package/src/vite-plugin-generate-build-manifest.mts +192 -0
- package/src/vite-plugin-inject-sb-ids-transform.mts +1 -1
- package/test/clients.test.mts +120 -0
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { Plugin } from "vite";
|
|
2
|
+
|
|
3
|
+
const BUILD_MANIFEST_MODULE_PATH = "./user-facing/build-manifest.js";
|
|
4
|
+
const VIRTUAL_MODULE_ID = "\0virtual:build-manifest.js";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* This plugin is used to stub the build manifest module. It creates a virtual module
|
|
8
|
+
* for the build manifest module and returns an empty object.
|
|
9
|
+
*
|
|
10
|
+
* This is meant to be used to avoid errors when the build manifest module is not found.
|
|
11
|
+
* This plugin only runs in dev server mode.
|
|
12
|
+
*/
|
|
13
|
+
export const buildManifestStubPlugin = (): Plugin => {
|
|
14
|
+
return {
|
|
15
|
+
name: "build-manifest-stub",
|
|
16
|
+
enforce: "pre",
|
|
17
|
+
apply: "serve",
|
|
18
|
+
|
|
19
|
+
resolveId(source) {
|
|
20
|
+
if (source === BUILD_MANIFEST_MODULE_PATH) {
|
|
21
|
+
return VIRTUAL_MODULE_ID;
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
load(id) {
|
|
25
|
+
if (id === VIRTUAL_MODULE_ID) {
|
|
26
|
+
return "export default {}";
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
};
|
|
@@ -224,8 +224,8 @@ async function analyzeModuleGraph(
|
|
|
224
224
|
{ content: string; binary: ArrayBuffer }
|
|
225
225
|
> = new Map(),
|
|
226
226
|
): Promise<AnalysisResult> {
|
|
227
|
-
// Avoid circular dependencies
|
|
228
|
-
if (visited.has(url)) {
|
|
227
|
+
// Avoid circular dependencies and skip the shared library's build manifest reference
|
|
228
|
+
if (visited.has(url) || url.endsWith("/user-facing/build-manifest.js")) {
|
|
229
229
|
return {
|
|
230
230
|
dependencies: new Set(),
|
|
231
231
|
content: "",
|
|
@@ -474,6 +474,13 @@ const wellKnownPackages = new Map<string, string>([
|
|
|
474
474
|
["react-dom", "https://esm.sh/react-dom@18.2.0"],
|
|
475
475
|
["react/jsx-runtime", "https://esm.sh/react@18.2.0/jsx-runtime"],
|
|
476
476
|
["react/jsx-dev-runtime", "https://esm.sh/react@18.2.0/jsx-dev-runtime"],
|
|
477
|
+
["./user-facing/build-manifest.js", "/assets/build-manifest.js"],
|
|
478
|
+
["/assets/user-facing/build-manifest.js", "/assets/build-manifest.js"],
|
|
479
|
+
]);
|
|
480
|
+
|
|
481
|
+
const packagesToExcludeFromCdnRedirect = new Set<string>([
|
|
482
|
+
"./user-facing/build-manifest.js",
|
|
483
|
+
"/assets/user-facing/build-manifest.js",
|
|
477
484
|
]);
|
|
478
485
|
|
|
479
486
|
const react18CdnUrl = "https://esm.sh/react@18.2.0";
|
|
@@ -773,8 +780,12 @@ export async function superblocksCdnPlugin(
|
|
|
773
780
|
// Externalize modules specified in the import map
|
|
774
781
|
// The cdn: prefix ensures they're properly resolved to the CDN URL
|
|
775
782
|
if (imports.includes(id)) {
|
|
783
|
+
const shouldRedirectToCdn = !packagesToExcludeFromCdnRedirect.has(id);
|
|
776
784
|
debug(`Externalizing module for CDN resolution: ${id}`);
|
|
777
|
-
return {
|
|
785
|
+
return {
|
|
786
|
+
id: `${shouldRedirectToCdn ? "cdn:" : ""}${id}`,
|
|
787
|
+
external: true,
|
|
788
|
+
};
|
|
778
789
|
}
|
|
779
790
|
|
|
780
791
|
return null;
|
package/src/index.ts
CHANGED
|
@@ -11,6 +11,8 @@ export {
|
|
|
11
11
|
fetchApplicationWithComponents,
|
|
12
12
|
fetchApplications,
|
|
13
13
|
fetchCurrentUser,
|
|
14
|
+
getDefaultBranchInfo,
|
|
15
|
+
getCurrentBranchInfo,
|
|
14
16
|
pushApi,
|
|
15
17
|
pushApplication,
|
|
16
18
|
registerComponents,
|
|
@@ -20,8 +22,10 @@ export {
|
|
|
20
22
|
type ApplicationWrapper,
|
|
21
23
|
type Branch,
|
|
22
24
|
type Branches,
|
|
25
|
+
type BranchSource,
|
|
23
26
|
type CodeModeApplicationWrapper,
|
|
24
27
|
type CommitDto,
|
|
28
|
+
type CurrentBranch,
|
|
25
29
|
type GetCommitsResponseBody,
|
|
26
30
|
type MultiPageApplicationWrapper,
|
|
27
31
|
type MultiPageApplicationWrapperWithComponents,
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { parse } from "@babel/parser";
|
|
3
|
+
import { getClientApiId } from "@superblocksteam/library-shared";
|
|
4
|
+
import { resolveLanguageSpecificStepContentFromBlocks } from "@superblocksteam/util";
|
|
5
|
+
import { getPageName } from "@superblocksteam/vite-plugin-file-sync";
|
|
6
|
+
import {
|
|
7
|
+
extractIdentifierPathsFromApi,
|
|
8
|
+
extractApiDependencies,
|
|
9
|
+
} from "@superblocksteam/vite-plugin-file-sync/binding-extraction";
|
|
10
|
+
import {
|
|
11
|
+
getScope,
|
|
12
|
+
extractImportsFromAst,
|
|
13
|
+
} from "@superblocksteam/vite-plugin-file-sync/parsing";
|
|
14
|
+
import { yellow, red } from "colorette";
|
|
15
|
+
import fg from "fast-glob";
|
|
16
|
+
import fs from "fs-extra";
|
|
17
|
+
import { createLogger } from "vite";
|
|
18
|
+
import yaml from "yaml";
|
|
19
|
+
import { getLogger } from "./dev-utils/dev-logger.mjs";
|
|
20
|
+
import type { ParseResult } from "@babel/parser";
|
|
21
|
+
import type { File } from "@babel/types";
|
|
22
|
+
import type {
|
|
23
|
+
DeleteMeLibraryApi,
|
|
24
|
+
StaticScope,
|
|
25
|
+
} from "@superblocksteam/library-shared/types";
|
|
26
|
+
import type { Plugin } from "vite";
|
|
27
|
+
|
|
28
|
+
export const scopeFileBaseName = "scope.ts";
|
|
29
|
+
export const apiFileBaseName = "api.yaml";
|
|
30
|
+
|
|
31
|
+
type ApiDependency = {
|
|
32
|
+
apiName: string;
|
|
33
|
+
params: string[];
|
|
34
|
+
dependencies: string[];
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Vite plugin that generates a build manifest for the application.
|
|
39
|
+
*
|
|
40
|
+
* This plugin will:
|
|
41
|
+
* 1. Read all api.yaml and api.yml files in the application
|
|
42
|
+
* 2. Read all scope.ts files in the application
|
|
43
|
+
* 3. Generate a build manifest for the application
|
|
44
|
+
* 4. Write the build manifest to a file in the build output directory
|
|
45
|
+
*
|
|
46
|
+
* The build manifest is a JSON object with the following properties:
|
|
47
|
+
* - apis: a map of all apis in the application keyed by their file path
|
|
48
|
+
* - apiDependencies: an array where each item represents an api and its dependencies
|
|
49
|
+
*
|
|
50
|
+
* @param root - The root directory of the application
|
|
51
|
+
* @returns A Vite plugin that generates a build manifest for the application
|
|
52
|
+
*/
|
|
53
|
+
export function generateBuildManifestPlugin(root: string) {
|
|
54
|
+
const viteLogger = createLogger();
|
|
55
|
+
const logger = getLogger();
|
|
56
|
+
viteLogger.info = (msg: string) => logger.info(msg);
|
|
57
|
+
viteLogger.warn = (msg: string) => {
|
|
58
|
+
logger.warn(yellow(msg));
|
|
59
|
+
};
|
|
60
|
+
viteLogger.warnOnce = (msg: string) => {
|
|
61
|
+
logger.warn(yellow(msg));
|
|
62
|
+
};
|
|
63
|
+
viteLogger.error = (msg: string) => {
|
|
64
|
+
logger.error(red(msg));
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
viteLogger.clearScreen = () => {};
|
|
68
|
+
|
|
69
|
+
const scopesByPage: Record<string, StaticScope | null> = {};
|
|
70
|
+
const apiFiles: Record<string, DeleteMeLibraryApi> = {};
|
|
71
|
+
let buildManifest: {
|
|
72
|
+
apis: Record<string, { api: DeleteMeLibraryApi; scopeId: string }>;
|
|
73
|
+
apiDependencies: ApiDependency[];
|
|
74
|
+
} = { apis: {}, apiDependencies: [] };
|
|
75
|
+
|
|
76
|
+
return {
|
|
77
|
+
name: "sb-generate-build-manifest",
|
|
78
|
+
apply: "build",
|
|
79
|
+
enforce: "pre",
|
|
80
|
+
|
|
81
|
+
async buildStart() {
|
|
82
|
+
const apiDocuments = await fg(["**/api.yaml", "**/api.yml"], {
|
|
83
|
+
cwd: root,
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
for (const apiFilePath of apiDocuments) {
|
|
87
|
+
const absoluteApiFilePath = path.join(root, apiFilePath);
|
|
88
|
+
|
|
89
|
+
const document = await fs.readFile(absoluteApiFilePath, "utf-8");
|
|
90
|
+
const apiPb = yaml.parse(document);
|
|
91
|
+
|
|
92
|
+
await resolveLanguageSpecificStepContentFromBlocks(
|
|
93
|
+
path.dirname(absoluteApiFilePath),
|
|
94
|
+
apiPb.blocks ?? [],
|
|
95
|
+
{},
|
|
96
|
+
);
|
|
97
|
+
|
|
98
|
+
const pageName = getPageName(apiFilePath);
|
|
99
|
+
apiPb.metadata.id = getClientApiId(apiPb.metadata.name, pageName);
|
|
100
|
+
apiFiles[apiFilePath] = { apiPb, pageName };
|
|
101
|
+
}
|
|
102
|
+
},
|
|
103
|
+
|
|
104
|
+
transform(code: string, id: string) {
|
|
105
|
+
if (id.endsWith(scopeFileBaseName)) {
|
|
106
|
+
const ast = parse(code, {
|
|
107
|
+
sourceType: "module",
|
|
108
|
+
sourceFilename: id,
|
|
109
|
+
plugins: [["typescript", {}]],
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
const scopeFileMeta: {
|
|
113
|
+
code: string;
|
|
114
|
+
ast: ParseResult<File>;
|
|
115
|
+
imports: Record<string, boolean>;
|
|
116
|
+
} = {
|
|
117
|
+
code,
|
|
118
|
+
ast,
|
|
119
|
+
imports: extractImportsFromAst(ast),
|
|
120
|
+
};
|
|
121
|
+
const scope = getScope(id, scopeFileMeta);
|
|
122
|
+
|
|
123
|
+
scopesByPage[getPageName(id)] = scope;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
return code;
|
|
127
|
+
},
|
|
128
|
+
|
|
129
|
+
async generateBundle() {
|
|
130
|
+
const allApiNames = getAllUniqueApiNames(apiFiles);
|
|
131
|
+
|
|
132
|
+
const allApis = Object.entries(apiFiles).reduce(
|
|
133
|
+
(acc, [id, api]) => {
|
|
134
|
+
acc[id] = {
|
|
135
|
+
api,
|
|
136
|
+
scopeId: scopesByPage[api.pageName]?.scopeId ?? "",
|
|
137
|
+
};
|
|
138
|
+
return acc;
|
|
139
|
+
},
|
|
140
|
+
{} as Record<string, { api: DeleteMeLibraryApi; scopeId: string }>,
|
|
141
|
+
);
|
|
142
|
+
|
|
143
|
+
const deps = await getApiDependencies(allApiNames, apiFiles);
|
|
144
|
+
|
|
145
|
+
buildManifest = {
|
|
146
|
+
apis: allApis,
|
|
147
|
+
apiDependencies: deps,
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
this.emitFile({
|
|
151
|
+
type: "prebuilt-chunk",
|
|
152
|
+
fileName: "assets/build-manifest.js",
|
|
153
|
+
code: `export default ${JSON.stringify(buildManifest)}`,
|
|
154
|
+
exports: ["default"],
|
|
155
|
+
});
|
|
156
|
+
},
|
|
157
|
+
} as Plugin;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function getAllUniqueApiNames(
|
|
161
|
+
apiFiles: Record<string, DeleteMeLibraryApi>,
|
|
162
|
+
): string[] {
|
|
163
|
+
const allApiNamesSet = new Set<string>(
|
|
164
|
+
Object.values(apiFiles).map((api) => api.apiPb.metadata.name),
|
|
165
|
+
);
|
|
166
|
+
return Array.from(allApiNamesSet);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
async function getApiDependencies(
|
|
170
|
+
apiNames: string[],
|
|
171
|
+
apiFiles: Record<string, DeleteMeLibraryApi>,
|
|
172
|
+
): Promise<ApiDependency[]> {
|
|
173
|
+
const deps: ApiDependency[] = [];
|
|
174
|
+
|
|
175
|
+
// TODO: This logic is a copy of the extractApiParamsAndDependencies function in the
|
|
176
|
+
// fileSyncVitePlugin (https://github.com/superblocksteam/superblocks/blob/474c0b11d79a1d6988864fb20d5ec26f92931fde/packages/vite-plugin-file-sync/src/file-sync-vite-plugin.ts#L261-L280).
|
|
177
|
+
//
|
|
178
|
+
// This logic should be refactored so that it can be shared between the two plugins.
|
|
179
|
+
await Promise.all([
|
|
180
|
+
...Object.values(apiFiles).map(async (api) => {
|
|
181
|
+
const bindings = await extractIdentifierPathsFromApi(api);
|
|
182
|
+
const apiDependencies = extractApiDependencies(apiNames, bindings);
|
|
183
|
+
deps.push({
|
|
184
|
+
apiName: api.apiPb.metadata.name,
|
|
185
|
+
params: bindings,
|
|
186
|
+
dependencies: apiDependencies,
|
|
187
|
+
});
|
|
188
|
+
}),
|
|
189
|
+
]);
|
|
190
|
+
|
|
191
|
+
return deps;
|
|
192
|
+
}
|
|
@@ -29,7 +29,7 @@ const routesFileBaseName = "routes.json";
|
|
|
29
29
|
export async function injectSuperblocksIdsPlugin(root: string) {
|
|
30
30
|
const viteLogger = createLogger();
|
|
31
31
|
const logger = getLogger();
|
|
32
|
-
viteLogger.info = logger.info;
|
|
32
|
+
viteLogger.info = (msg: string) => logger.info(msg);
|
|
33
33
|
viteLogger.warn = (msg: string) => {
|
|
34
34
|
logger.warn(yellow(msg));
|
|
35
35
|
};
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import { expect } from "chai";
|
|
4
|
+
import { describe, it } from "mocha";
|
|
5
|
+
import { BranchSource, getCurrentBranchInfo } from "../src/client.js";
|
|
6
|
+
import { getCurrentGitBranch } from "../src/version-control.mjs";
|
|
7
|
+
import type { SuperblocksDevEnvironmentConfig } from "@superblocksteam/util";
|
|
8
|
+
|
|
9
|
+
// The .superblocks folder is located in the 'test' directory, so we need to prefix the path in order to find it.
|
|
10
|
+
const testPathPrefix = "test";
|
|
11
|
+
const superblocksTestFolder = path.join(
|
|
12
|
+
process.cwd(),
|
|
13
|
+
testPathPrefix,
|
|
14
|
+
".superblocks",
|
|
15
|
+
);
|
|
16
|
+
const devEnvBranch = "dev-branch";
|
|
17
|
+
const currentGitBranch = await getCurrentGitBranch();
|
|
18
|
+
|
|
19
|
+
describe("get current branch info", () => {
|
|
20
|
+
let createdSuperblocksFolder = false;
|
|
21
|
+
|
|
22
|
+
before(async function () {
|
|
23
|
+
// Make the .superblocks folder in the test directory, if it is missing. It should be git-ignored.
|
|
24
|
+
if (!fs.existsSync(superblocksTestFolder)) {
|
|
25
|
+
fs.mkdirSync(superblocksTestFolder, { recursive: true });
|
|
26
|
+
createdSuperblocksFolder = true;
|
|
27
|
+
}
|
|
28
|
+
// Create a dev-environment.json file in the .superblocks folder.
|
|
29
|
+
const devEnvironmentJson = path.join(
|
|
30
|
+
superblocksTestFolder,
|
|
31
|
+
"dev-environment.json",
|
|
32
|
+
);
|
|
33
|
+
fs.writeFileSync(
|
|
34
|
+
devEnvironmentJson,
|
|
35
|
+
JSON.stringify({
|
|
36
|
+
branch: devEnvBranch,
|
|
37
|
+
configType: "DEV_ENVIRONMENT",
|
|
38
|
+
} as SuperblocksDevEnvironmentConfig),
|
|
39
|
+
);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
after(async function () {
|
|
43
|
+
// Delete the .superblocks folder in the test directory.
|
|
44
|
+
if (createdSuperblocksFolder && fs.existsSync(superblocksTestFolder)) {
|
|
45
|
+
fs.rmSync(superblocksTestFolder, { recursive: true });
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it("should find the dev environment config and return a valid branch info object", async () => {
|
|
50
|
+
const branchInfo = await getCurrentBranchInfo(undefined, testPathPrefix);
|
|
51
|
+
|
|
52
|
+
expect(branchInfo.branchName).to.equal(devEnvBranch);
|
|
53
|
+
expect(branchInfo.source).to.equal(BranchSource.DEV_ENVIRONMENT);
|
|
54
|
+
expect(branchInfo.userSpecifiedBranch).to.be.undefined;
|
|
55
|
+
expect(branchInfo.isDefinedInDevEnvironmentConfig()).to.be.true;
|
|
56
|
+
expect(branchInfo.isDevEnvironmentWithUserSpecifiedBranch()).to.be.false;
|
|
57
|
+
expect(branchInfo.isDefaultBranch()).to.be.false;
|
|
58
|
+
|
|
59
|
+
// Call it again to make sure it has the same properties
|
|
60
|
+
const branchInfo2 = await getCurrentBranchInfo(undefined, testPathPrefix);
|
|
61
|
+
expect(branchInfo).to.deep.equal(branchInfo2);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it("should find the dev environment config and include the user-specified branch parameter", async () => {
|
|
65
|
+
const userBranch = "test-user-branch";
|
|
66
|
+
const branchInfo = await getCurrentBranchInfo(userBranch, testPathPrefix);
|
|
67
|
+
|
|
68
|
+
expect(branchInfo.branchName).to.equal(devEnvBranch);
|
|
69
|
+
expect(branchInfo.source).to.equal(BranchSource.DEV_ENVIRONMENT);
|
|
70
|
+
expect(branchInfo.userSpecifiedBranch).to.equal(userBranch);
|
|
71
|
+
expect(branchInfo.isDefinedInDevEnvironmentConfig()).to.be.true;
|
|
72
|
+
expect(branchInfo.isDevEnvironmentWithUserSpecifiedBranch()).to.be.true;
|
|
73
|
+
expect(branchInfo.isDefaultBranch()).to.be.false;
|
|
74
|
+
|
|
75
|
+
// Call it again to make sure it's the same object
|
|
76
|
+
const branchInfo2 = await getCurrentBranchInfo(userBranch, testPathPrefix);
|
|
77
|
+
expect(branchInfo).to.deep.equal(branchInfo2);
|
|
78
|
+
|
|
79
|
+
// Call it again without the test path will find the user supplied branch
|
|
80
|
+
const branchInfo3 = await getCurrentBranchInfo(userBranch);
|
|
81
|
+
expect(branchInfo3.branchName).to.equal(userBranch);
|
|
82
|
+
expect(branchInfo3.source).to.equal(BranchSource.COMMAND_LINE);
|
|
83
|
+
expect(branchInfo3.userSpecifiedBranch).to.equal(userBranch);
|
|
84
|
+
expect(branchInfo3.isDefinedInDevEnvironmentConfig()).to.be.false;
|
|
85
|
+
expect(branchInfo3.isDevEnvironmentWithUserSpecifiedBranch()).to.be.false;
|
|
86
|
+
expect(branchInfo3.isDefaultBranch()).to.be.false;
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it("should not find a dev environment config and return an info with our git branch", async () => {
|
|
90
|
+
const branchInfo = await getCurrentBranchInfo();
|
|
91
|
+
expect(branchInfo.branchName).to.equal(currentGitBranch);
|
|
92
|
+
expect(branchInfo.source).to.equal(BranchSource.GIT_REPO);
|
|
93
|
+
expect(branchInfo.userSpecifiedBranch).to.be.undefined;
|
|
94
|
+
expect(branchInfo.isDefinedInDevEnvironmentConfig()).to.be.false;
|
|
95
|
+
expect(branchInfo.isDevEnvironmentWithUserSpecifiedBranch()).to.be.false;
|
|
96
|
+
expect(branchInfo.isDefaultBranch()).to.be.false;
|
|
97
|
+
|
|
98
|
+
// Call it again to make sure it's the same object
|
|
99
|
+
const branchInfo2 = await getCurrentBranchInfo();
|
|
100
|
+
expect(branchInfo).to.deep.equal(branchInfo2);
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it("should not find a dev environment config and return an info with the user-specified branch", async () => {
|
|
104
|
+
const userBranch = "test-user-branch";
|
|
105
|
+
expect(userBranch).to.not.equal(devEnvBranch);
|
|
106
|
+
expect(userBranch).to.not.equal(currentGitBranch);
|
|
107
|
+
|
|
108
|
+
const branchInfo = await getCurrentBranchInfo(userBranch);
|
|
109
|
+
expect(branchInfo.branchName).to.equal(userBranch);
|
|
110
|
+
expect(branchInfo.source).to.equal(BranchSource.COMMAND_LINE);
|
|
111
|
+
expect(branchInfo.userSpecifiedBranch).to.equal(userBranch);
|
|
112
|
+
expect(branchInfo.isDefinedInDevEnvironmentConfig()).to.be.false;
|
|
113
|
+
expect(branchInfo.isDevEnvironmentWithUserSpecifiedBranch()).to.be.false;
|
|
114
|
+
expect(branchInfo.isDefaultBranch()).to.be.false;
|
|
115
|
+
|
|
116
|
+
// Call it again to make sure it's the same object
|
|
117
|
+
const branchInfo2 = await getCurrentBranchInfo(userBranch);
|
|
118
|
+
expect(branchInfo).to.deep.equal(branchInfo2);
|
|
119
|
+
});
|
|
120
|
+
});
|