diff --git a/packages/generator-teams/src/app/GeneratorTeamsApp.ts b/packages/generator-teams/src/app/GeneratorTeamsApp.ts index 72626f16..8e7a5544 100644 --- a/packages/generator-teams/src/app/GeneratorTeamsApp.ts +++ b/packages/generator-teams/src/app/GeneratorTeamsApp.ts @@ -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'); @@ -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"]; @@ -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); diff --git a/packages/generator-teams/src/app/templates/package.json b/packages/generator-teams/src/app/templates/package.json index 4e885c1a..17a7b726 100644 --- a/packages/generator-teams/src/app/templates/package.json +++ b/packages/generator-teams/src/app/templates/package.json @@ -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", diff --git a/packages/generator-teams/src/app/templates/src/client/jest.config.js b/packages/generator-teams/src/app/templates/src/client/jest.config.js index 4dcc9de9..eb99809b 100644 --- a/packages/generator-teams/src/app/templates/src/client/jest.config.js +++ b/packages/generator-teams/src/app/templates/src/client/jest.config.js @@ -1,5 +1,4 @@ module.exports = { - name: "client", displayName: "client", rootDir: "./../../", globals: { @@ -10,6 +9,7 @@ module.exports = { } } }, + testEnvironment: "jsdom", preset: "ts-jest/presets/js-with-ts", snapshotSerializers: [ "enzyme-to-json/serializer" diff --git a/packages/generator-teams/src/app/templates/src/server/jest.config.js b/packages/generator-teams/src/app/templates/src/server/jest.config.js index c6c441c4..c4d04d52 100644 --- a/packages/generator-teams/src/app/templates/src/server/jest.config.js +++ b/packages/generator-teams/src/app/templates/src/server/jest.config.js @@ -1,5 +1,4 @@ module.exports = { - name: "server", displayName: "server", rootDir: "./../../", globals: { diff --git a/packages/generator-teams/src/tab/templates/src/client/{tabName}/__tests__/{tabReactComponentName}.spec.tsx b/packages/generator-teams/src/tab/templates/src/client/{tabName}/__tests__/{tabReactComponentName}.spec.tsx index 3c4a5d90..e08a7db7 100644 --- a/packages/generator-teams/src/tab/templates/src/client/{tabName}/__tests__/{tabReactComponentName}.spec.tsx +++ b/packages/generator-teams/src/tab/templates/src/client/{tabName}/__tests__/{tabReactComponentName}.spec.tsx @@ -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%>"; @@ -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(); }); });