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