cenfun / monocart-reporter

A playwright test reporter (Node.js)
https://cenfun.github.io/monocart-reporter/
MIT License
195 stars 11 forks source link

sourceFilter is not filtering all files #60

Closed azamat-sharapov closed 10 months ago

azamat-sharapov commented 1 year ago

I'm using Global Coverage Report and trying to filter out some files, which are not coming from src/ directory.

image

On the screenshot above, you can see that Modal.vue and Confirmation.vue are included in the report, but they shouldn't be. Their type is js. Although, in sourceFilter, I'm allowing only .vue files. When I try to console.log inside sourceFilter, I don't get Modal.vue and Confirmation.vue. Following is from config:

{
  coverage: {
    lcov: true,
    sourceFilter: (sourcePath: string) => {
      return /^src\/.*\.(vue)$/.test(sourcePath)
    },
    entryFilter: (entry: { url: string }) => {
      const url = new URL(entry.url)

      const isLocalChunk = url.pathname.match(
        /^\/assets\/.+-\w+\.js$/
      )
      return isLocalChunk !== null && url.origin === BASE_URL
    },
  }
}
cenfun commented 1 year ago

It seems that the Modal.vue and Confirmation.vue are not source files (not included in sourcemap), you should using 'entryFilter' not 'sourceFilter' Please check last column (URL) in your screenshot, the entry files should be started with "http://localhost:8000/assets", and the source files should be started with "../../src/" Hope it helps you.

azamat-sharapov commented 1 year ago

@cenfun I put console.log inside sourceFilter and entryFilter and this is what happens:

Logs: ``` Running 2 tests using 1 worker ✓ 1 [setup] › auth.setup.ts:9:6 › create a user (709ms) -> CREATED USER: test-user-f23inh@example.com ✓ 2 [chromium] › settings.spec.ts:9:8 › Settings › General tab (1.5s) ENTRY URL: http://localhost:8000/nr.js ENTRY URL: http://localhost:8000/assets/index-51db30cf.js ENTRY URL: http://localhost:8000/assets/use-tree-walker-77c7bb6b.js ENTRY URL: http://localhost:8000/assets/SettingsGeneralView-8c66d994.js ENTRY URL: http://localhost:8000/assets/SettingsLayout-ce9a19a8.js ENTRY URL: http://localhost:8000/assets/DesktopSidebar.vue_vue_type_script_setup_true_lang-3f879619.js ENTRY URL: http://localhost:8000/assets/menu-5b29dc78.js ENTRY URL: http://localhost:8000/assets/use-tracked-pointer-67c461f0.js ENTRY URL: http://localhost:8000/assets/use-outside-click-53df7abe.js ENTRY URL: http://localhost:8000/assets/VerticalNavMobile.vue_vue_type_script_setup_true_lang-b390cd8a.js ENTRY URL: http://localhost:8000/assets/transition-6858523c.js ENTRY URL: http://localhost:8000/assets/Modal.vue_vue_type_script_setup_true_lang-dbab2fea.js ENTRY URL: http://localhost:8000/assets/Input.vue_vue_type_script_setup_true_lang-469dc22b.js ENTRY URL: http://localhost:8000/assets/Button.vue_vue_type_script_setup_true_lang-d1fbc861.js 2 passed (3.1s) [MCR] generating report data ... [MCR] generating global coverage report ... SOURCE PATH node_modules/.pnpm/@vue+shared@3.3.4/node_modules/@vue/shared/dist/shared.esm-bundler.js SOURCE PATH src/App.vue SOURCE PATH packages/action-status/src/composables/use-collection-maker.ts SOURCE PATH packages/action-status/src/composables/use-whitelist.ts SOURCE PATH packages/action-status/src/composables/use-messages-getters.ts SOURCE PATH packages/action-status/src/composables/use-status-tracker.ts SOURCE PATH packages/action-status/src/composables/use-status-changer.ts SOURCE PATH packages/action-status/src/store.ts SOURCE PATH packages/action-status/src/action-handler.ts SOURCE PATH src/stores/index.ts SOURCE PATH packages/locale/src/global-messages.ts SOURCE PATH packages/locale/src/i18n.ts SOURCE PATH packages/ui/src/Notifier.ts SOURCE PATH packages/api/src/api.ts SOURCE PATH packages/api/src/auth.ts SOURCE PATH packages/jsonapi/src/indexing.ts SOURCE PATH packages/jsonapi/src/_relationship.utils.ts SOURCE PATH packages/jsonapi/src/utils.ts SOURCE PATH packages/api/src/user.ts SOURCE PATH packages/jsonapi/src/_replace.records.mutations.ts SOURCE PATH packages/jsonapi/src/records.mutations.ts SOURCE PATH node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/isPlainObject.js SOURCE PATH src/stores/utils.ts SOURCE PATH src/stores/user/user.store.ts SOURCE PATH packages/api/src/display-settings.ts SOURCE PATH src/stores/display-settings/display-settings.store.ts SOURCE PATH packages/api/src/account.ts SOURCE PATH src/stores/account/account.store.ts SOURCE PATH src/stores/auth/composables/use-invite.ts SOURCE PATH src/stores/auth/auth.store.ts SOURCE PATH src/routes/guards.ts SOURCE PATH src/routes/index.ts SOURCE PATH packages/locale/src/yup.ts SOURCE PATH src/main.ts SOURCE PATH src/views/settings-general-view/AccountForm.vue SOURCE PATH packages/ui/src/utils/use-modal-toggler.ts SOURCE PATH src/views/settings-general-view/AccountEdit.vue SOURCE PATH src/views/SettingsGeneralView.vue SOURCE PATH src/components/settings-navigation.ts SOURCE PATH src/layouts/composables/use-navigation.ts SOURCE PATH src/layouts/SettingsLayout.vue SOURCE PATH src/components/sidebar-navigation.ts SOURCE PATH src/components/MobileSidebar.vue SOURCE PATH src/components/composables/use-logout.ts SOURCE PATH src/components/Topbar.vue SOURCE PATH packages/ui/src/VerticalNavMobile.vue SOURCE PATH packages/ui/src/Input.vue SOURCE PATH packages/action-status/src/action-tracker.ts SOURCE PATH packages/ui/src/Message.vue SOURCE PATH packages/ui/src/composables/use-validation-schema.ts SOURCE PATH packages/ui/src/Form.vue SOURCE PATH packages/ui/src/Button.vue [MCR] generating test report ... [MCR] test results: Test Report ┌───────────────┬───────────────────────┐ │ ├ Tests │ 2 │ │ │ ├ Passed │ 2 (100.0%) │ │ │ ├ Flaky │ 0 (0.0%) │ │ │ ├ Skipped │ 0 (0.0%) │ │ │ └ Failed │ 0 (0.0%) │ │ ├ Steps │ 51 │ │ ├ Suites │ 2 │ │ │ ├ Projects │ 2 │ │ │ ├ Files │ 2 │ │ │ ├ Describes │ 1 │ │ │ └ Shards │ 0 │ │ ├ Retries │ 0 │ │ ├ Errors │ 0 │ │ ├ Logs │ 27 │ │ ├ Attachments │ 0 │ │ ├ Playwright │ v1.37.1 │ │ ├ Date │ 9/21/2023, 9:27:58 AM │ │ └ Duration │ 4.10s │ └───────────────┴───────────────────────┘ [MCR] coverage: test-results/coverage/index.html Coverage Report - Test Report (global) [MCR] json report: test-results/index.json [MCR] html report: test-results/index.html [MCR] view report: npx monocart show-report test-results/index.html ```
Report screenshot: ![image](https://github.com/cenfun/monocart-reporter/assets/3023661/3672f6eb-cd83-4a65-bb7f-7bfad68c9e6c)

As you can see, Modal.vue is included in coverage report, but it shouldn't be. The problem is, I am not able to filter it out, because everything starts with http://localhost:8000/assets in entryFilter(). I can however filter some components in sourceFilter(), for example packages/ui/src/Input.vue, but for some reason, packages/ui/src/Modal.vue is not going through sourceFilter(). BTW, it's production build.

Modal.vue source ```vue ```
cenfun commented 1 year ago

There is no Modal.vue in your screenshot. Does the file Modal.vue you mentioned is Modal.vue_vue_type_script_setup_true_lang-dbab2fea.js?

Basically, here's the logic First, providing all entry files which starting with 'http://localhost:8000/assets' and filtering with entryFilter Then, tring to load sourcemaps (inline or linked) for each entry file and decoding sourcemaps for source files (filtering with sourceFilter)

obviously, Modal.vue_vue_type_script_setup_true_lang-dbab2fea.js is entry file, pleace check if it has map file like Modal.vue_vue_type_script_setup_true_lang-dbab2fea.js.map, otherwise we can not get the source file Modal.vue

sorry, I can't explain it clearly, or can you provide us a demo repo so we can reproduce it locally?

azamat-sharapov commented 1 year ago

There is no Modal.vue in your screenshot. Does the file Modal.vue you mentioned is Modal.vue_vue_type_script_setup_true_lang-dbab2fea.js?

Yes, because that's how it's called after compilation (Vite build). Original file in the source is Modal.vue, that's why I called it Modal.vue

otherwise we can not get the source file Modal.vue

Well, I can see that Modal.vue is not going through sourceFilter() at all, so maybe it shouldn't be included in the report at all (you can see it missing in logs)? The Modal.vue comes from completely different directory outside of src/, but some files in src/ are importing it and it is ended up in localhost:8000/assets for that reason.

It's is not small project, it's typescript monorepo. However, I will try to create minimal repro later. Thanks for your help so far

cenfun commented 10 months ago

feel free to reopen it if any updates

azamat-sharapov commented 8 months ago

Update: with build.minify = false for Vite, this problem is solved ✅