Closed m0jimo closed 7 months ago
I am not familar with PnPTelemetry - what is that?
https://pnp.github.io/pnpjs/sp/behaviors/#telemetry https://github.com/pnp/sp-dev-fx-controls-react/issues/475
Here is the part in pnpjs
Even if I dont use a type, it has no difference - see screenshot from IntellJ
Our network blocks CORS requests to other locations, sot it throws erros in DevTools unless it is not disabled.
Hi, the Telemetry in PnPjs and the PnPTelemetry you reference are not related. So that code that you have won't do anything for PnPjs. That's specific to the Reusable Controls library.
In PnPjs we default include Telemetry in some of our existing Behaviors such as the SPFx(), DefaultInit() behaviors. If you don't want to use Telemetry, you'd need to specify your own default behaviors as noted in our docs
If you're using the SPFx behavior, you can see which ones we are including by default here
Upps. You are right. I mixed up two projects. I'm sorry. My code is from https://pnp.github.io/sp-dev-fx-controls-react/. Thanks for clarifing it. I'll move to another channel :-o.
Just to further clarify for anyone who might see this later. PnPjs doesn't do any network calls to add Telemetry, rather we add a header to the call to "tag" it using a very redacted string that indicates the endpoint that was called.
Closing this issue as answered. If you have additional questions or we did not answer your question, please open a new issue, ref this issue, and provide any additional details available. Thank you!
This issue is locked for inactivity or age. If you have a related issue please open a new issue and reference this one. Closed issues are not tracked.
What version of PnPjs library you are using
3.x
Minor Version Number
16
Target environment
SharePoint Framework
Additional environment details
I'm using:
--experimental-vm-modules
.eslint.cjs - standard configuration but with cjs extension, otherwise Jest fails
.eslint.cjs
```js require("@rushstack/eslint-config/patch/modern-module-resolution"); const userRules = { "no-nested-ternary": 2, "no-useless-concat": 0, "@typescript-eslint/no-unused-vars": [ 0, { vars: "all", // Unused function arguments often indicate a mistake in JavaScript code. However in TypeScript code, // the compiler catches most of those mistakes, and unused arguments are fairly common for type signatures // that are overriding a base class method or implementing an interface. args: "none" } ], "no-unused-expressions": 0 }; module.exports = { extends: ["@microsoft/eslint-config-spfx/lib/profiles/react"], parserOptions: { tsconfigRootDir: __dirname }, overrides: [ { files: ["*.ts", "*.tsx"], parser: "@typescript-eslint/parser", parserOptions: { project: "./tsconfig.json", ecmaVersion: 2018, sourceType: "module" }, rules: { "@typescript-eslint/ban-ts-comment": "off", "@typescript-eslint/no-empty-function": [ "error", { allow: ["arrowFunctions"] } ], "react/self-closing-comp": [ "error", { component: false, html: false } ], // 'no-unused-vars': "off", // 'no-unused-variable': "off", // 'no-unused-variable': [true, {'ignore-pattern': '^_'}], // Prevent usage of the JavaScript null value, while allowing code to access existing APIs that may require null. https://www.npmjs.com/package/@rushstack/eslint-plugin "@rushstack/no-new-null": 1, // Require Jest module mocking APIs to be called before any other statements in their code block. https://www.npmjs.com/package/@rushstack/eslint-plugin "@rushstack/hoist-jest-mock": 1, // Require regular expressions to be constructed from string constants rather than dynamically building strings at runtime. https://www.npmjs.com/package/@rushstack/eslint-plugin-security "@rushstack/security/no-unsafe-regexp": 1, // STANDARDIZED BY: @typescript-eslint\eslint-plugin\dist\configs\recommended.json "@typescript-eslint/adjacent-overload-signatures": 1, // STANDARDIZED BY: @typescript-eslint\eslint-plugin\dist\configs\recommended.json // // CONFIGURATION: By default, these are banned: String, Boolean, Number, Object, Symbol "@typescript-eslint/ban-types": [ 1, { extendDefaults: false, types: { String: { message: "Use 'string' instead", fixWith: "string" }, Boolean: { message: "Use 'boolean' instead", fixWith: "boolean" }, Number: { message: "Use 'number' instead", fixWith: "number" }, Object: { message: "Use 'object' instead, or else define a proper TypeScript type:" }, Symbol: { message: "Use 'symbol' instead", fixWith: "symbol" }, Function: { message: "The 'Function' type accepts any function-like value.\nIt provides no type safety when calling the function, which can be a common source of bugs.\nIt also accepts things like class declarations, which will throw at runtime as they will not be called with 'new'.\nIf you are expecting the function to accept certain arguments, you should explicitly define the function shape." } } } ], // RATIONALE: Code is more readable when the type of every variable is immediately obvious. // Even if the compiler may be able to infer a type, this inference will be unavailable // to a person who is reviewing a GitHub diff. This rule makes writing code harder, // but writing code is a much less important activity than reading it. // // STANDARDIZED BY: @typescript-eslint\eslint-plugin\dist\configs\recommended.json "@typescript-eslint/explicit-function-return-type": [ 1, { allowExpressions: true, allowTypedFunctionExpressions: true, allowHigherOrderFunctions: false } ], // STANDARDIZED BY: @typescript-eslint\eslint-plugin\dist\configs\recommended.json // Rationale to disable: although this is a recommended rule, it is up to dev to select coding style. // Set to 1 (warning) or 2 (error) to enable. "@typescript-eslint/explicit-member-accessibility": 0, // STANDARDIZED BY: @typescript-eslint\eslint-plugin\dist\configs\recommended.json "@typescript-eslint/no-array-constructor": 1, // STANDARDIZED BY: @typescript-eslint\eslint-plugin\dist\configs\recommended.json // // RATIONALE: The "any" keyword disables static type checking, the main benefit of using TypeScript. // This rule should be suppressed only in very special cases such as JSON.stringify() // where the type really can be anything. Even if the type is flexible, another type // may be more appropriate such as "unknown", "{}", or "Record.tsconfig
```js { "extends": "./node_modules/@microsoft/rush-stack-compiler-4.5/includes/tsconfig-web.json", "compilerOptions": { "esModuleInterop": true, "forceConsistentCasingInFileNames": true, "module": "esnext", "target": "es5", "moduleResolution": "node", "jsx": "react", "declaration": true, "sourceMap": true, "experimentalDecorators": true, "skipLibCheck": true, "outDir": "lib", "inlineSources": false, "strictNullChecks": false, "noUnusedLocals": false, "noImplicitAny": true, "typeRoots": [ "./types", "./node_modules/@types", "./node_modules/@microsoft" ], "types": [ "webpack-env", "jest" ], "lib": [ "es6", "dom", "es2015.collection", "es2015.promise", "es2017.object" ], "allowSyntheticDefaultImports": true }, "include": [ "src/**/*.ts", "src/**/*.tsx" ], "exclude": ["node_modules", "**/*.spec.ts", "**/*.test.ts"] } ```jest.config.ts
```js import type {Config} from 'jest'; const config: Config = { transform: { "^.+\\.(ts|tsx)$": ["ts-jest", { useESM: true }] }, testRegex: "(/(/__tests__/.*|(\\.|/)(test|spec))\\.jsx?$/.*|(\\.|/)(test|spec))\\.(ts?|tsx?)$", moduleFileExtensions: ["ts", "tsx", "js", "json"], moduleNameMapper: { "[\\.(css|scss)$](file://.(css|scss)$)": "identity-obj-proxy" }, modulePathIgnorePatterns:["src/webparts/****/services"], extensionsToTreatAsEsm: [".ts"] }; export default config; ```Question/Request
I’ve successfully configured a Jest for testing my SPFx project but the last main remaining issue is failing on disabling a Telemetry.
If I leave telemetry options untouched, it runs all the test but if I disable it fails the test and I haven’t found a way how to configure the environment to avoid touching this part by Jest.
I found that getInstance i function not part of the package but fetched from URL, so it doesn't exists in our solution.
I guess it is related to configuration of TypeScript/Eslint. I tried to ignore folder with servives, disable eslint on page, create an interface (probably not correctly) but with no success.
I'd be happy for any additional hint. Thanks.