Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃悰 BUG: Vitest reports invalid coverage when more than one test files are run #5825

Open
gourgouris opened this issue May 14, 2024 · 0 comments
Labels
bug Something that isn't working

Comments

@gourgouris
Copy link

Which Cloudflare product(s) does this pertain to?

Workers Vitest Integration

What version(s) of the tool(s) are you using?

@cloudflare/vitest-pool-workers: 0.2.9, wrangler: 3.55.0, @vitest/coverage-istanbul: 1.5.3, vitest: 1.5.3

What version of Node are you using?

20.12.2

What operating system and version are you using?

Win 11

Describe the Bug

Observed behavior

When more than one coverage reports are generated by istanbul, when merged, they show correct coverage of the first test file.

Expected behavior

It is common practice to split tests into multiple files. It is also acceptable to have more than one routes in a worker. So, when testing different routes from different test files, I'd expect coverage to be reported correctly for all of them.

Steps to reproduce

Copied scaffold from fixtures/vitest-pool-workers-examples/basics-unit-integration-self

vitest.config.ts - just enable istanbul because v8 (default) is not supported

export default defineWorkersConfig({
	test: {
		poolOptions: {
			workers: {
				singleWorker: true,
				miniflare: { compatibilityFlags: ["service_binding_extra_handlers"],},
				wrangler: { configPath: "./wrangler.toml",},
			},
		},
		coverage: { provider: 'istanbul',},
	},
});

index.ts - multiple routes, that point to different ts files

import { greetA } from "./a";
import { greetB } from "./b";

export default {
	async fetch(request, env, ctx) {
		if (request.url.endsWith('a')) {
			return new Response(greetA(request));	
		}
		return new Response(greetB(request));	
	},
} satisfies ExportedHandler;
a.ts
export function greetA(request: Request): string { return `A馃憢 ${request.url}`; }
b.ts
export function greetB(request: Request): string { return `B馃憢 ${request.url}`; }

now I want to test route a and route b from different test files:

a.test.ts
it("routes to a", async () => {
	const response = await SELF.fetch("http://example.com/a");
	expect(await response.text()).toBe("A馃憢 http://example.com/a");
});
b.test.ts
it("routes to b", async () => {
	const response = await SELF.fetch("http://example.com/b");
	expect(await response.text()).toBe("B馃憢 http://example.com/b");
});

I use VSCode Vitest extension and "run with coverage", but should be the same from cli.
I get the following when running "all" tests

image

file b.ts shows 0% coverage, although b.test.ts run and succeeded. If I run only b.test.ts, then it shows 100% coverage

I tried a similar setup without wrangler at all, to see if its something related to vitest only, but it worked as expected.

Please provide a link to a minimal reproduction

No response

Please provide any relevant error logs

No response

@gourgouris gourgouris added the bug Something that isn't working label May 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something that isn't working
Projects
Status: Untriaged
Development

No branches or pull requests

1 participant