Skip to content

Commit

Permalink
✅ Fixed tests, due to promises/hooks in new Teams JS SDK
Browse files Browse the repository at this point in the history
  • Loading branch information
wictorwilen committed May 23, 2022
1 parent b523bab commit 49e5203
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 14 deletions.
16 changes: 9 additions & 7 deletions packages/generator-teams/src/app/GeneratorTeamsApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ import { CoreFilesUpdaterFactory } from './coreFilesUpdater/CoreFilesUpdaterFact

const yosay = require('yosay');

// optimize App Insights performance
process.env.APPLICATION_INSIGHTS_NO_DIAGNOSTIC_CHANNEL = "none";
process.env.APPLICATION_INSIGHTS_NO_STATSBEAT = "true";
import * as AppInsights from 'applicationinsights';
// optimize App Insights performance
process.env.APPLICATION_INSIGHTS_NO_DIAGNOSTIC_CHANNEL = "none";
process.env.APPLICATION_INSIGHTS_NO_STATSBEAT = "true";
import * as AppInsights from 'applicationinsights';


let pkg: any = require('../../package.json');
Expand Down Expand Up @@ -51,14 +51,14 @@ export class GeneratorTeamsApp extends Generator {
!(process.env.YOTEAMS_TELEMETRY_OPTOUT === "1" ||
process.env.YOTEAMS_TELEMETRY_OPTOUT === "true")) {


// Set up the App Insights client
const config = AppInsights.setup("6d773b93-ff70-45c5-907c-8edae9bf90eb");
config.setInternalLogging(false, false);

// Add a random session ID to the telemetry
AppInsights.defaultClient.context.tags['ai.session.id'] = crypto.randomBytes(24).toString('base64');

// Delete unnecessary telemetry data
delete AppInsights.defaultClient.context.tags["ai.cloud.roleInstance"];
delete AppInsights.defaultClient.context.tags["ai.cloud.role"];
Expand Down Expand Up @@ -533,7 +533,9 @@ export class GeneratorTeamsApp extends Generator {
["enzyme-adapter-react-16", "^1.11.2"],
["enzyme-to-json", "^3.3.5"],
["jest", "^28.1.0"],
["ts-jest", "^28.0.2"]
["ts-jest", "^28.0.2"],
["jest-environment-jsdom", "^28.1.0"],
["cheerio", "1.0.0-rc.10"]
], this.fs);

Yotilities.addScript("test", "jest", this.fs);
Expand Down
2 changes: 1 addition & 1 deletion packages/generator-teams/src/app/templates/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"@types/express-session": "~1.17.4",
"@types/morgan": "~1.9.3",
"@types/react": "16.8.10",
"@types/react-dom": "16.8.3",
"@types/react-dom": "^16.9.7",
"browser-sync": "^2.26.5",
"fancy-log": "^2.0.0",
"file-loader": "~6.2.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
module.exports = {
name: "client",
displayName: "client",
rootDir: "./../../",
globals: {
Expand All @@ -10,6 +9,7 @@ module.exports = {
}
}
},
testEnvironment: "jsdom",
preset: "ts-jest/presets/js-with-ts",
snapshotSerializers: [
"enzyme-to-json/serializer"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
module.exports = {
name: "server",
displayName: "server",
rootDir: "./../../",
globals: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import * as React from "react";
import { shallow, mount } from "enzyme";
import toJson from "enzyme-to-json";
import { Header } from "@fluentui/react-northstar";
import { act } from "react-dom/test-utils";


import { <%=tabReactComponentName%> } from "../<%=tabReactComponentName%>";

Expand All @@ -21,15 +23,19 @@ describe("<%=tabReactComponentName%> Component", () => {
});

// Mocking Sample
it("should show alert on button click", () => {
it("should show alert on button click", async () => {
window.alert = jest.fn();

const component = mount(<<%=tabReactComponentName%> />);
let component;
await act (async () => {
component = mount(<<%=tabReactComponentName%> />);
});

const button = component.find("button");
button.simulate("click");

button.simulate("click");

expect(window.alert).toHaveBeenCalledWith("It worked!");

component.unmount();
});
});

0 comments on commit 49e5203

Please sign in to comment.