Skip to content

Commit 9488a54

Browse files
committed
Unify e2e tests into one file
1 parent dee555e commit 9488a54

File tree

4 files changed

+140
-148
lines changed

4 files changed

+140
-148
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"start:web": "office-addin-debugging start manifest.xml web",
2424
"stop": "office-addin-debugging stop manifest.xml",
2525
"test": "npm run test:unit && npm run test:e2e",
26-
"test:e2e": "mocha -r ts-node/register test/end-to-end/*.ts",
26+
"test:e2e": "mocha -r ts-node/register test/end-to-end/tests.ts",
2727
"test:unit": "mocha -r ts-node/register test/unit/*.test.ts",
2828
"validate": "office-addin-manifest validate manifest.xml",
2929
"watch": "webpack --mode development --watch"

test/end-to-end/debugging-test.ts

Lines changed: 0 additions & 53 deletions
This file was deleted.

test/end-to-end/tests.ts

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
import * as assert from "assert";
2+
import * as fs from "fs";
3+
import { parseNumber } from "office-addin-cli";
4+
import { AppType, startDebugging, stopDebugging } from "office-addin-debugging";
5+
import { toOfficeApp } from "office-addin-manifest";
6+
import { pingTestServer } from "office-addin-test-helpers";
7+
import { closeDesktopApplication } from "./src/test-helpers";
8+
import { connectToWebsocket, enableDebugging, pauseDebugging } from "./src/debugger-websocket";
9+
import * as officeAddinTestServer from "office-addin-test-server";
10+
import * as path from "path";
11+
12+
/* global process, describe, before, it, after */
13+
const host: string = "excel";
14+
const manifestPath = path.resolve(`${process.cwd()}/test/end-to-end/test-manifest.xml`);
15+
const port: number = 4201;
16+
const testDataFile: string = `${process.cwd()}/test/end-to-end/src/test-data.json`;
17+
const testJsonData = JSON.parse(fs.readFileSync(testDataFile).toString());
18+
const testServer = new officeAddinTestServer.TestServer(port);
19+
let testValues: any = [];
20+
21+
describe("Test Excel Custom Functions", function () {
22+
describe("UI Tests", function () {
23+
before(`Setup test environment and sideload ${host}`, async function () {
24+
this.timeout(0);
25+
// Start test server and ping to ensure it's started
26+
const testServerStarted = await testServer.startTestServer(true /* mochaTest */);
27+
const serverResponse = await pingTestServer(port);
28+
assert.strictEqual(serverResponse["status"], 200);
29+
assert.strictEqual(testServerStarted, true);
30+
31+
// Call startDebugging to start dev-server and sideload
32+
const devServerCmd = `npm run dev-server -- --config ./test/end-to-end/webpack.config.js`;
33+
const devServerPort = parseNumber(process.env.npm_package_config_dev_server_port || 3000);
34+
const options = {
35+
appType: AppType.Desktop,
36+
app: toOfficeApp(host),
37+
devServerCommandLine: devServerCmd,
38+
devServerPort: devServerPort,
39+
enableDebugging: false,
40+
};
41+
await startDebugging(manifestPath, options);
42+
});
43+
describe("Get test results for custom functions and validate results", function () {
44+
it("should get results from the taskpane application", async function () {
45+
this.timeout(0);
46+
// Expecting six result values
47+
testValues = await testServer.getTestResults();
48+
assert.strictEqual(testValues.length, 6);
49+
});
50+
it("ADD function should return expected value", async function () {
51+
assert.strictEqual(testJsonData.functions.ADD.result, testValues[0].Value);
52+
});
53+
it("CLOCK function should return expected value", async function () {
54+
// Check that captured values are different to ensure the function is streaming
55+
assert.notStrictEqual(testValues[1].Value, testValues[2].Value);
56+
// Check if the returned string contains 'AM', 'PM', or 'GMT', indicating it's a time-stamp
57+
assert.strictEqual(
58+
testValues[1].Value.includes(testJsonData.functions.CLOCK.result.amString) ||
59+
testValues[1].Value.includes(testJsonData.functions.CLOCK.result.pmString) ||
60+
testValues[1].Value.includes(testJsonData.functions.CLOCK.result.timeZoneString),
61+
true,
62+
"Found timestamp indicator string in first value '" + testValues[1].Value + "'"
63+
);
64+
assert.strictEqual(
65+
testValues[2].Value.includes(testJsonData.functions.CLOCK.result.amString) ||
66+
testValues[2].Value.includes(testJsonData.functions.CLOCK.result.pmString) ||
67+
testValues[2].Value.includes(testJsonData.functions.CLOCK.result.timeZoneString),
68+
true,
69+
"Found timestamp indicator string in second value '" + testValues[2].Value + "'"
70+
);
71+
});
72+
it("INCREMENT function should return expected value", async function () {
73+
// Check that captured values are different to ensure the function is streaming
74+
assert.notStrictEqual(testValues[3].Value, testValues[4].Value);
75+
// Check to see that both captured streaming values are divisible by 4
76+
assert.strictEqual(0, testValues[3].Value % testJsonData.functions.INCREMENT.result);
77+
assert.strictEqual(0, testValues[4].Value % testJsonData.functions.INCREMENT.result);
78+
});
79+
it("LOG function should return expected value", async function () {
80+
assert.strictEqual(testJsonData.functions.LOG.result, testValues[5].Value);
81+
});
82+
});
83+
after("Teardown test environment", async function () {
84+
this.timeout(0);
85+
// Stop the test server
86+
const stopTestServer = await testServer.stopTestServer();
87+
assert.strictEqual(stopTestServer, true);
88+
89+
// Close excel
90+
const applicationClosed = await closeDesktopApplication();
91+
assert.strictEqual(applicationClosed, true);
92+
93+
// Unregister the add-in
94+
await stopDebugging(manifestPath);
95+
});
96+
});
97+
describe("Debugger Tests", function () {
98+
before(`Setup test environment and sideload ${host}`, async function () {
99+
this.timeout(0);
100+
// Call startDebugging to start dev-server and sideload
101+
const devServerCmd: string = `npm run dev-server -- --config ./test/end-to-end/webpack.config.js --env testType=debugger`;
102+
const devServerPort: number = 3001;
103+
const options = {
104+
appType: AppType.Desktop,
105+
app: toOfficeApp(host),
106+
devServerCommandLine: devServerCmd,
107+
devServerPort: devServerPort,
108+
enableDebugging: true,
109+
};
110+
await startDebugging(manifestPath, options);
111+
});
112+
describe("Test Debugger", function () {
113+
let ws: WebSocket;
114+
before("Open websocket connection to Debugger", async function () {
115+
this.timeout(60 * 1000);
116+
ws = await connectToWebsocket();
117+
assert.notStrictEqual(ws, undefined, "Unable to connect to the websocket.");
118+
});
119+
it("enable debugging", async function () {
120+
await enableDebugging(ws);
121+
});
122+
it("pause debugging", async function () {
123+
await pauseDebugging(ws);
124+
});
125+
after("Close websocket connection", async function () {
126+
ws.close();
127+
});
128+
});
129+
after("Teardown test environment", async function () {
130+
this.timeout(0);
131+
// Close excel
132+
const applicationClosed = await closeDesktopApplication();
133+
assert.strictEqual(applicationClosed, true);
134+
135+
// Unregister the add-in
136+
await stopDebugging(manifestPath);
137+
});
138+
});
139+
});

test/end-to-end/ui-test.ts

Lines changed: 0 additions & 94 deletions
This file was deleted.

0 commit comments

Comments
 (0)