-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathaction_tests.ts
138 lines (118 loc) · 5.19 KB
/
action_tests.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/*-------------------------------------------------------------------------------------------------
* Copyright (C) 2023 Intel Corporation. All rights reserved.
* Licensed under the Apache License 2.0. See LICENSE in the project root for license information.
* SPDX-License-Identifier: Apache-2.0
*-----------------------------------------------------------------------------------------------*/
import { expect } from "chai";
import { ShowSuggestionAction, SuggestionExample } from "../src/actions/show_suggestion";
import { GetUserInputAction } from "../src/actions/get_user_input";
import { ShowDepRecipeAction } from "../src/actions/show_dep_recipe";
import { ConfigEnvChangeAction } from "../src/actions/config_env_change";
import { ConfigOptionChangeAction } from "../src/actions/config_option_change";
import { BuilderArgsChangeAction } from "../src/actions/args_change";
import { WEBINIZER_TEST_HOME } from "../src/constants";
import { Project } from "../src/project";
import { BuildStepChangeAction, BuildStepRegion } from "../src/actions/build_step_change";
import { FileChangeAction, FileChangeManager, FileRegion } from "../src/actions/file_change";
import fs from "graceful-fs";
import { backupFolderSync, deleteFolder, renameFolder } from "../src/helper";
import path from "path";
import { IAction, IBuilder } from "webinizer";
const TEST_ACTION_ASSETS_DIR = `${WEBINIZER_TEST_HOME}/assets/actions`;
describe("action", () => {
before(() => {
//Backup the "assets/actions" folder
backupFolderSync(TEST_ACTION_ASSETS_DIR, `${WEBINIZER_TEST_HOME}/assets/.actions`);
});
after(() => {
//Delete the older "assets/actions" and restore it from backup
deleteFolder(TEST_ACTION_ASSETS_DIR);
renameFolder(`${WEBINIZER_TEST_HOME}/assets/.actions`, TEST_ACTION_ASSETS_DIR);
});
it("BuilderArgsChangeActionTest", async () => {
const proj = new Project(path.join(TEST_ACTION_ASSETS_DIR, "BuilderArgsChangeAction"));
const action = new BuilderArgsChangeAction(
proj,
"",
[{ option: "-msimd128", value: null, type: "merge" }],
0,
true
);
const result = await (action as IAction).apply();
expect(result).to.equal(true);
expect(
(proj.config.getBuildConfigForTarget("static").builders as IBuilder[])[0].args[0]
).to.equal("-msimd128");
});
it("BuildStepChangeActionTest", async () => {
const proj = new Project(path.join(TEST_ACTION_ASSETS_DIR, "BuildStepChangeAction"));
const region = new BuildStepRegion(1);
const newBuildSteps = [
{
__type__: "CMakeBuilder",
id: 1,
desc: "cmake",
command: "emcmake cmake",
args: "",
rootBuildFilePath: "${projectRoot}",
},
];
const action = new BuildStepChangeAction(proj, "", region, newBuildSteps);
const result = await (action as IAction).apply();
expect(result).to.equal(true);
expect((proj.config.getBuildConfigForTarget("static").builders as IBuilder[])[1].type).to.equal(
"CMakeBuilder"
);
});
it("ConfigEnvChangeActionTest", async () => {
const proj = new Project(path.join(TEST_ACTION_ASSETS_DIR, "ConfigEnvChangeAction"));
const action = new ConfigEnvChangeAction(proj, "", {
cflags: [{ option: "-msimd128", value: null, type: "delete" }],
});
const result = await (action as IAction).apply();
expect(result).to.equal(true);
expect(proj.config.getBuildConfigForTarget("static").getEnv("cflags")).to.not.include(
"-msimd128"
);
expect(proj.config.getOverallEnv("cflags")).to.not.include("-msimd128");
});
it("ConfigOptionChangeActionTest", async () => {
const proj = new Project(path.join(TEST_ACTION_ASSETS_DIR, "ConfigOptionChangeAction"));
const action = new ConfigOptionChangeAction(proj, "", { needMainLoop: false });
const result = await (action as IAction).apply();
expect(result).to.equal(true);
expect(proj.config.getBuildConfigForTarget("static").getOption("needMainLoop")).to.equal(false);
});
it("FileChangeActionTest", async () => {
const region = new FileRegion(
path.join(TEST_ACTION_ASSETS_DIR, "FileChangeAction", "testfile"),
0,
0
);
const newContent = "Test line 1\nTest line 2";
const action = new FileChangeAction(new FileChangeManager(), "", region, newContent);
const result = await (action as IAction).apply();
expect(result).to.equal(true);
expect(fs.readFileSync(region.file, "utf-8")).to.include(newContent);
});
it("GetUserInputActionTest", async () => {
const action = new GetUserInputAction();
const result = await (action as IAction).apply();
expect(result).to.equal(false);
});
it("ShowDepRecipeActionTest", async () => {
const action = new ShowDepRecipeAction("Unit test for ShowDepRecipeAction", ["Dep1", "Dep2"]);
const result = await (action as IAction).apply();
expect(result).to.equal(true);
});
it("ShowSuggestionActionTest", async () => {
const action = new ShowSuggestionAction(
"error",
"Unit test for ShowSuggestionAction",
new SuggestionExample("ShowSuggestionAction Test", "Test ShowSuggestionAction"),
null
);
const result = await (action as IAction).apply();
expect(result).to.equal(true);
});
});