-
Notifications
You must be signed in to change notification settings - Fork 9
Secure registry, improve tests, update packages #90
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,2 @@ | ||
| registry=https://registry.npmjs.org/ | ||
| registry=https://office.pkgs.visualstudio.com/_packaging/OfficeDev/npm/registry/ | ||
| always-auth=true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,69 +1,115 @@ | ||
| import functionsJsonData from "./test-data.json"; | ||
| import { pingTestServer, sendTestResults } from "office-addin-test-helpers"; | ||
| import { closeWorkbook, sleep } from "./test-helpers"; | ||
| import { addErrorResult, closeWorkbook, formatError, sleep } from "./test-helpers"; | ||
|
|
||
| /* global Office, document, Excel, run, navigator */ | ||
| const customFunctionsData = (<any>functionsJsonData).functions; | ||
| const port: number = 4201; | ||
| let testValues = []; | ||
| let testValues: any[] = []; | ||
|
|
||
| Office.onReady(async () => { | ||
| document.getElementById("sideload-msg").style.display = "none"; | ||
| document.getElementById("app-body").style.display = "flex"; | ||
| document.getElementById("run").onclick = run; | ||
| document.getElementById("sideload-msg")!.style.display = "none"; | ||
| document.getElementById("app-body")!.style.display = "flex"; | ||
| document.getElementById("run")!.onclick = run; | ||
| addTestResult("UserAgent", navigator.userAgent); | ||
|
|
||
| const testServerResponse: object = await pingTestServer(port); | ||
| if (testServerResponse["status"] === 200) { | ||
| try { | ||
| const testServerResponse = (await pingTestServer(port)) as { status?: number }; | ||
| if (testServerResponse.status === 200) { | ||
| await runTest(); | ||
| } else { | ||
| addErrorResult(testValues, `Ping failed: ${JSON.stringify(testServerResponse)}`); | ||
| await sendTestResults(testValues, port).catch(() => {}); | ||
| } | ||
| } catch (err) { | ||
| addErrorResult(testValues, `Initialization failed: ${formatError(err)}`); | ||
| await sendTestResults(testValues, port).catch(() => {}); | ||
| } | ||
| }); | ||
|
|
||
| async function runTest(): Promise<void> { | ||
| try { | ||
| await runCfTests(); | ||
| await sendTestResults(testValues, port); | ||
| await closeWorkbook(); | ||
|
millerds marked this conversation as resolved.
|
||
| } catch (err) { | ||
| testValues = []; | ||
| addErrorResult(testValues, `runTest failed: ${formatError(err)}`); | ||
| await sendTestResults(testValues, port).catch(() => {}); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| async function runCfTests(): Promise<void> { | ||
| // Exercise custom functions | ||
| await Excel.run(async (context) => { | ||
| for (let key in customFunctionsData) { | ||
| const formula: string = customFunctionsData[key].formula; | ||
| const range = context.workbook.getSelectedRange(); | ||
| range.formulas = [[formula]]; | ||
| await context.sync(); | ||
| for (let key in customFunctionsData) { | ||
| const formula: string = customFunctionsData[key].formula; | ||
| const readCount: number = customFunctionsData[key].streaming != undefined ? 2 : 1; | ||
| let capturedValues: any[] = []; | ||
|
|
||
| for (let attempt = 0; attempt < 3; attempt++) { | ||
| await Excel.run(async (context: Excel.RequestContext) => { | ||
| const range = context.workbook.getSelectedRange(); | ||
| range.formulas = [[formula]]; | ||
| await context.sync(); | ||
| }); | ||
|
|
||
| await sleep(5000); | ||
|
|
||
| // Check to if this is a streaming function | ||
| await readCFData(key, customFunctionsData[key].streaming != undefined ? 2 : 1); | ||
| capturedValues = await readCFData(readCount); | ||
| const hasCalcError = capturedValues.some((value) => typeof value === "string" && value.includes("#CALC!")); | ||
| if (!hasCalcError) { | ||
| break; | ||
| } | ||
|
|
||
| // Re-enter formula when custom function registration/evaluation is still warming up. | ||
| await sleep(2000); | ||
| } | ||
| }); | ||
|
|
||
| for (const value of capturedValues) { | ||
| addTestResult(key, value); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| export async function readCFData(cfName: string, readCount: number): Promise<void> { | ||
| await Excel.run(async (context) => { | ||
| export async function readCFData(readCount: number): Promise<any[]> { | ||
| return Excel.run(async (context: Excel.RequestContext) => { | ||
| const capturedValues: any[] = []; | ||
|
|
||
| // if this is a streaming function, we want to capture two values so we can | ||
| // validate the function is indeed streaming | ||
| for (let i = 0; i < readCount; i++) { | ||
| try { | ||
| const range = context.workbook.getSelectedRange(); | ||
| if (i > 0) { | ||
| // For streaming functions, wait for the next emitted value. | ||
| await sleep(5000); | ||
| } | ||
|
|
||
| const range = context.workbook.getSelectedRange(); | ||
| let value: any = undefined; | ||
|
|
||
| // Retry a few times when Excel still reports transient calculation errors. | ||
| for (let retry = 0; retry < 4; retry++) { | ||
| range.load("values"); | ||
| await context.sync(); | ||
| value = range.values?.[0]?.[0]; | ||
|
|
||
| await sleep(5000); | ||
| if (typeof value !== "string" || !value.includes("#CALC!")) { | ||
| break; | ||
| } | ||
|
|
||
| addTestResult(cfName, range.values[0][0]); | ||
| Promise.resolve(); | ||
| } catch { | ||
| Promise.reject(); | ||
| await sleep(2000); | ||
| } | ||
|
|
||
| capturedValues.push(value); | ||
| } | ||
|
|
||
| return capturedValues; | ||
| }); | ||
| } | ||
|
|
||
| function addTestResult(resultName: string, resultValue: any) { | ||
| var data = {}; | ||
| var nameKey = "Name"; | ||
| var valueKey = "Value"; | ||
| data[nameKey] = resultName; | ||
| data[valueKey] = resultValue; | ||
| function addTestResult(name: string, value: any) { | ||
| const data = { | ||
| name: name, | ||
| value: value, | ||
| }; | ||
| testValues.push(data); | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.