Skip to content

Commit 47e2550

Browse files
committed
Improve tests, use secure registry, and update packages.
1 parent 6d3b960 commit 47e2550

14 files changed

Lines changed: 2531 additions & 2130 deletions

.npmrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
registry=https://registry.npmjs.org/
1+
registry=https://office.pkgs.visualstudio.com/_packaging/OfficeDev/npm/registry/
2+
always-auth=true

.vscode/launch.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"--colors",
1515
"${workspaceFolder}/test/end-to-end",
1616
"-r",
17-
"ts-node/register",
17+
"${workspaceFolder}/test/register-ts-node.js",
1818
"${workspaceFolder}/test/end-to-end/*.ts"
1919
],
2020
"internalConsoleOptions": "openOnSessionStart",
@@ -33,7 +33,7 @@
3333
"--colors",
3434
"${workspaceFolder}/test/unit",
3535
"-r",
36-
"ts-node/register",
36+
"${workspaceFolder}/test/register-ts-node.js",
3737
"${workspaceFolder}/test/unit/*.test.ts"
3838
],
3939
"internalConsoleOptions": "openOnSessionStart",

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ Custom functions enable you to add new functions to Excel by defining those func
44

55
This repository contains the source code used by the [Yo Office generator](https://github.com/OfficeDev/generator-office) when you create a new custom functions project. You can also use this repository as a sample to base your own custom functions project from if you choose not to use the generator. For more detailed information about custom functions in Excel, see the [Custom functions overview](https://learn.microsoft.com/office/dev/add-ins/excel/custom-functions-overview) article in the Office Add-ins documentation or see the [additional resources](#additional-resources) section of this repository.
66

7+
## npm registry auth
8+
Run the following command to get the authenticator for the first time:
9+
10+
`npm install --global @microsoft/artifacts-npm-credprovider --registry https://pkgs.dev.azure.com/artifacts-public/23934c1b-a3b5-4b70-9dd3-d1bef4cc72a0/_packaging/AzureArtifacts/npm/registry/`
11+
12+
Run `artifacts-npm-credprovider` to authenticate for the npm registry.
13+
714
## Debugging custom functions
815

916
This template supports debugging custom functions from [Visual Studio Code](https://code.visualstudio.com/). For more information see [Custom functions debugging](https://aka.ms/custom-functions-debug). For general information on debugging task panes and other Office Add-in parts, see [Test and debug Office Add-ins](https://learn.microsoft.com/office/dev/add-ins/testing/test-debug-office-add-ins).

package-lock.json

Lines changed: 2427 additions & 2029 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
"start": "office-addin-debugging start manifest.xml",
2525
"stop": "office-addin-debugging stop manifest.xml",
2626
"test": "npm run test:unit && npm run test:e2e",
27-
"test:e2e": "mocha -r ts-node/register test/end-to-end/tests.ts",
28-
"test:unit": "mocha -r ts-node/register test/unit/*.test.ts",
27+
"test:e2e": "mocha -r ./test/register-ts-node.js test/end-to-end/tests.ts",
28+
"test:unit": "mocha -r ./test/register-ts-node.js test/unit/*.test.ts",
2929
"validate": "office-addin-manifest validate manifest.xml",
3030
"watch": "webpack --mode development --watch"
3131
},
@@ -46,22 +46,22 @@
4646
"@types/office-runtime": "^1.0.35",
4747
"acorn": "^8.5.0",
4848
"babel-loader": "^10.1.1",
49-
"copy-webpack-plugin": "^12.0.2",
49+
"copy-webpack-plugin": "^14.0.0",
5050
"custom-functions-metadata-plugin": "^2.1.2",
51-
"eslint-plugin-office-addins": "^4.0.3",
51+
"eslint-plugin-office-addins": "^4.0.10",
5252
"file-loader": "^6.2.0",
5353
"html-loader": "^5.0.0",
5454
"html-webpack-plugin": "^5.6.0",
5555
"mocha": "^11.7.4",
56-
"office-addin-cli": "^2.0.6",
57-
"office-addin-debugging": "^6.0.6",
58-
"office-addin-dev-certs": "^2.0.6",
59-
"office-addin-lint": "^3.0.6",
60-
"office-addin-manifest": "^2.1.2",
61-
"office-addin-mock": "^3.0.6",
62-
"office-addin-prettier-config": "^2.0.1",
63-
"office-addin-test-helpers": "^2.0.3",
64-
"office-addin-test-server": "^2.0.3",
56+
"office-addin-cli": "^2.0.10",
57+
"office-addin-debugging": "^6.1.2",
58+
"office-addin-dev-certs": "^2.0.10",
59+
"office-addin-lint": "^3.0.10",
60+
"office-addin-manifest": "^2.1.6",
61+
"office-addin-mock": "^3.0.10",
62+
"office-addin-prettier-config": "^2.0.5",
63+
"office-addin-test-helpers": "^2.0.7",
64+
"office-addin-test-server": "^2.0.7",
6565
"os-browserify": "^0.3.0",
6666
"process": "^0.11.10",
6767
"request": "^2.88.2",
@@ -70,7 +70,7 @@
7070
"typescript": "^5.4.2",
7171
"webpack": "^5.105.0",
7272
"webpack-cli": "^5.1.4",
73-
"webpack-dev-server": "5.2.5"
73+
"webpack-dev-server": "^6.0.0"
7474
},
7575
"prettier": "office-addin-prettier-config",
7676
"browserslist": [

test/end-to-end/src/debugger-websocket.ts

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,25 @@
11
import * as assert from "assert";
22
import { sleep } from "./test-helpers";
33
const WebSocket = require("ws");
4-
const request = require("request");
54

65
/* global require, console */
76
let connectionOpened = false;
87
let messageId = 0;
98
const limitOfReconnectTries = 60;
109
let wsUrl: string | undefined;
1110

12-
function findUrl(jsonUrl: string): void {
13-
let options = { json: true };
14-
15-
request(jsonUrl, options, (error, res, body) => {
16-
if (!error && res.statusCode == 200) {
17-
wsUrl = body[0].webSocketDebuggerUrl;
11+
async function findUrl(jsonUrl: string): Promise<void> {
12+
try {
13+
const response = await fetch(jsonUrl, { signal: AbortSignal.timeout(1000) });
14+
if (!response.ok) {
15+
return;
1816
}
19-
});
17+
18+
const body = await response.json();
19+
wsUrl = body?.[0]?.webSocketDebuggerUrl;
20+
} catch {
21+
// Debugger endpoint may not be ready yet. Retry loop handles this.
22+
}
2023
}
2124

2225
export async function connectToWebsocket(reconnectTry: number = 1): Promise<WebSocket | undefined> {
@@ -25,7 +28,7 @@ export async function connectToWebsocket(reconnectTry: number = 1): Promise<WebS
2528

2629
while (!wsUrl && reconnectTry < limitOfReconnectTries) {
2730
console.log(`Attaching debugger to '${jsonUrl}'...`);
28-
findUrl(jsonUrl);
31+
await findUrl(jsonUrl);
2932
reconnectTry++;
3033
await sleep(1000);
3134
}
@@ -39,12 +42,12 @@ export async function connectToWebsocket(reconnectTry: number = 1): Promise<WebS
3942
connectionOpened = true;
4043
return resolve(ws);
4144
};
42-
ws.onerror = (err) => {
45+
ws.onerror = (err: any) => {
4346
if (connectionOpened) {
4447
assert.fail(`Websocket error: ${err.message}`);
4548
}
4649
};
47-
ws.onmessage = (response) => {
50+
ws.onmessage = (response: any) => {
4851
assert.strictEqual(
4952
JSON.parse(response.data).error,
5053
undefined,

test/end-to-end/src/test-helpers.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,18 @@ export async function closeWorkbook(): Promise<void> {
1515
}
1616
}
1717

18+
export type TestResult = {
19+
expectedValue: any;
20+
resultName: string;
21+
resultValue: any;
22+
};
23+
1824
export function addTestResult(testValues: any[], resultName: string, resultValue: any, expectedValue: any) {
19-
var data = {};
20-
data["expectedValue"] = expectedValue;
21-
data["resultName"] = resultName;
22-
data["resultValue"] = resultValue;
25+
const data: TestResult = {
26+
expectedValue,
27+
resultName,
28+
resultValue,
29+
};
2330
testValues.push(data);
2431
}
2532

test/end-to-end/src/test-taskpane.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ const port: number = 4201;
88
let testValues: any[] = [];
99

1010
Office.onReady(async () => {
11-
document.getElementById("sideload-msg").style.display = "none";
12-
document.getElementById("app-body").style.display = "flex";
13-
document.getElementById("run").onclick = run;
11+
document.getElementById("sideload-msg")!.style.display = "none";
12+
document.getElementById("app-body")!.style.display = "flex";
13+
document.getElementById("run")!.onclick = run;
1414
addTestResult("UserAgent", navigator.userAgent);
1515

1616
try {
17-
const testServerResponse: object = await pingTestServer(port);
18-
if (testServerResponse["status"] === 200) {
17+
const testServerResponse = (await pingTestServer(port)) as { status?: number };
18+
if (testServerResponse.status === 200) {
1919
await runCfTests();
2020
await sendTestResults(testValues, port);
2121
await closeWorkbook();
@@ -41,7 +41,7 @@ async function runCfTests(): Promise<void> {
4141

4242
await sleep(5000);
4343

44-
await readCFData(key, customFunctionsData[key].streaming != undefined ? 2 : 1);
44+
await readCFData(key, customFunctionsData[key].streaming !== undefined ? 2 : 1);
4545
}
4646
});
4747
} catch (err) {
@@ -66,10 +66,9 @@ export async function readCFData(cfName: string, readCount: number): Promise<voi
6666
}
6767

6868
function addTestResult(resultName: string, resultValue: any) {
69-
var data = {};
70-
var nameKey = "Name";
71-
var valueKey = "Value";
72-
data[nameKey] = resultName;
73-
data[valueKey] = resultValue;
69+
const data = {
70+
Name: resultName,
71+
Value: resultValue,
72+
};
7473
testValues.push(data);
7574
}

test/end-to-end/tests.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ describe("Test Excel Custom Functions", function () {
2626
this.timeout(0);
2727
// Start test server and ping to ensure it's started
2828
const testServerStarted = await testServer.startTestServer(true /* mochaTest */);
29-
const serverResponse = await pingTestServer(port);
30-
assert.strictEqual(serverResponse["status"], 200);
29+
const serverResponse = (await pingTestServer(port)) as { status?: number };
30+
assert.strictEqual(serverResponse.status, 200);
3131
assert.strictEqual(testServerStarted, true);
3232

3333
// Call startDebugging to start dev-server and sideload
@@ -45,7 +45,7 @@ describe("Test Excel Custom Functions", function () {
4545
describe("Get test results for custom functions and validate results", function () {
4646
it("should get results from the taskpane application", async function () {
4747
this.timeout(testResultsTimeout + 10000);
48-
let timeoutId: ReturnType<typeof setTimeout>;
48+
let timeoutId!: ReturnType<typeof setTimeout>;
4949
const timeoutPromise = new Promise<never>((_, reject) => {
5050
timeoutId = setTimeout(
5151
() =>
@@ -138,20 +138,22 @@ describe("Test Excel Custom Functions", function () {
138138
await startDebugging(manifestPathDebugging, options);
139139
});
140140
describe("Test Debugger", function () {
141-
let ws: WebSocket;
141+
let ws: WebSocket | undefined;
142142
before("Open websocket connection to Debugger", async function () {
143143
this.timeout(60 * 1000);
144144
ws = await connectToWebsocket();
145145
assert.notStrictEqual(ws, undefined, "Unable to connect to the websocket.");
146146
});
147147
it("enable debugging", async function () {
148+
assert.ok(ws, "WebSocket connection was not established.");
148149
await enableDebugging(ws);
149150
});
150151
it("pause debugging", async function () {
152+
assert.ok(ws, "WebSocket connection was not established.");
151153
await pauseDebugging(ws);
152154
});
153155
after("Close websocket connection", async function () {
154-
ws.close();
156+
ws?.close();
155157
});
156158
});
157159
after("Teardown test environment", async function () {

test/end-to-end/webpack.config.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ module.exports = async (env, options) => {
3131
extensions: [".ts", ".tsx", ".html", ".js"],
3232
fallback: {
3333
child_process: false,
34-
fs: false,
35-
os: require.resolve("os-browserify/browser"),
3634
},
3735
},
3836
module: {

0 commit comments

Comments
 (0)