Skip to content
1 change: 1 addition & 0 deletions e2e/browser-mode/fixtures/ports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export const BROWSER_PORTS = {
'reporter-watch': 5222,
'github-actions': 5224,
'browser-coverage-multiproject': 5228,
related: 5230,
} as const;

const browserPortValues = Object.values(BROWSER_PORTS);
Expand Down
13 changes: 13 additions & 0 deletions e2e/browser-mode/fixtures/related/rstest.config.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { defineConfig } from '@rstest/core';
import { BROWSER_PORTS } from '../ports';

export default defineConfig({
browser: {
enabled: true,
provider: 'playwright',
headless: true,
port: BROWSER_PORTS.related,
},
include: ['tests/**/*.test.ts'],
testTimeout: 30000,
});
8 changes: 8 additions & 0 deletions e2e/browser-mode/fixtures/related/tests/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { describe, expect, it } from '@rstest/core';
import { sayHi } from './src/index';

describe('browser related index', () => {
it('should greet index', () => {
expect(sayHi()).toBe('Hello, index!');
});
});
8 changes: 8 additions & 0 deletions e2e/browser-mode/fixtures/related/tests/other.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { describe, expect, it } from '@rstest/core';
import { sayBye } from './src/other';

describe('browser related other', () => {
it('should greet other', () => {
expect(sayBye()).toBe('Hello, other!');
});
});
3 changes: 3 additions & 0 deletions e2e/browser-mode/fixtures/related/tests/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { greet } from './shared';

export const sayHi = () => greet('index');
3 changes: 3 additions & 0 deletions e2e/browser-mode/fixtures/related/tests/src/other.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { greet } from './shared';

export const sayBye = () => greet('other');
1 change: 1 addition & 0 deletions e2e/browser-mode/fixtures/related/tests/src/shared.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const greet = (name: string) => `Hello, ${name}!`;
55 changes: 55 additions & 0 deletions e2e/browser-mode/related.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { dirname, join } from 'node:path';
import { fileURLToPath } from 'node:url';
import { describe, expect, it } from '@rstest/core';
import { runRstestCli } from '../scripts';

const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);

describe('browser mode - related', () => {
it('should filter browser tests by related source files', async () => {
const { cli, expectExecSuccess } = await runRstestCli({
command: 'rstest',
args: ['list', '--related', 'tests/src/index.ts', '--filesOnly'],
options: {
nodeOptions: {
cwd: join(__dirname, 'fixtures', 'related'),
env: {
CI: '',
GITHUB_ACTIONS: '',
},
},
},
});

await expectExecSuccess();

expect(
cli.stdout.split('\n').filter((line) => line.includes('.test.ts')),
).toEqual(['tests/index.test.ts']);
});

it('should not run the full browser suite when related finds no tests', async () => {
const { cli, expectExecFailed } = await runRstestCli({
command: 'rstest',
args: ['run', '--related', 'tests/src/missing.ts'],
options: {
nodeOptions: {
cwd: join(__dirname, 'fixtures', 'related'),
env: {
CI: '',
GITHUB_ACTIONS: '',
},
},
},
});

await expectExecFailed();

expect(cli.stderr).toContain('No test files found, exiting with code 1.');
expect(cli.log).toContain('related:');
expect(cli.log).toContain('tests/src/missing.ts');
expect(cli.log).not.toContain('index.test.ts');
expect(cli.log).not.toContain('other.test.ts');
});
});
8 changes: 8 additions & 0 deletions e2e/filter/fixtures-related-dynamic/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { describe, expect, it } from '@rstest/core';

describe('index', () => {
it('should transform late', async () => {
const { getLate } = await import('./src/late');
expect(getLate()).toBe('LATE');
});
});
8 changes: 8 additions & 0 deletions e2e/filter/fixtures-related-dynamic/other.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { describe, expect, it } from '@rstest/core';

describe('other', () => {
it('should transform other', async () => {
const { getOther } = await import('./src/other');
expect(getOther()).toBe('OTHER');
});
});
11 changes: 11 additions & 0 deletions e2e/filter/fixtures-related-dynamic/rstest.config.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { defineConfig } from '@rstest/core';

export default defineConfig({
tools: {
rspack: {
watchOptions: {
aggregateTimeout: 10,
},
},
},
});
3 changes: 3 additions & 0 deletions e2e/filter/fixtures-related-dynamic/src/late.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { transform } from './shared';

export const getLate = () => transform('late');
3 changes: 3 additions & 0 deletions e2e/filter/fixtures-related-dynamic/src/other.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { transform } from './shared';

export const getOther = () => transform('other');
1 change: 1 addition & 0 deletions e2e/filter/fixtures-related-dynamic/src/shared.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const transform = (value: string) => value.toUpperCase();
8 changes: 8 additions & 0 deletions e2e/filter/fixtures-related-mixed/browser/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { describe, expect, it } from '@rstest/core';
import { sayHi } from './src/index';

describe('browser project', () => {
it('should not be touched for node-only related sources', () => {
expect(sayHi()).toBe('Hello, browser!');
});
});
1 change: 1 addition & 0 deletions e2e/filter/fixtures-related-mixed/browser/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const sayHi = () => 'Hello, browser!';
8 changes: 8 additions & 0 deletions e2e/filter/fixtures-related-mixed/node/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { describe, expect, it } from '@rstest/core';
import { sayHi } from './src/index';

describe('node project', () => {
it('should run node related tests without loading browser mode', () => {
expect(sayHi()).toBe('Hello, node!');
});
});
1 change: 1 addition & 0 deletions e2e/filter/fixtures-related-mixed/node/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const sayHi = () => 'Hello, node!';
21 changes: 21 additions & 0 deletions e2e/filter/fixtures-related-mixed/rstest.config.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { defineConfig } from '@rstest/core';

export default defineConfig({
projects: [
{
name: 'node-project',
root: 'node',
include: ['**/*.test.ts'],
},
{
name: 'browser-project',
root: 'browser',
include: ['**/*.test.ts'],
browser: {
enabled: true,
provider: 'invalid' as unknown as 'playwright',
headless: true,
},
},
],
});
8 changes: 8 additions & 0 deletions e2e/filter/fixtures-related/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { describe, expect, it } from '@rstest/core';
import { sayHi } from './src/index';

describe('index', () => {
it('should greet index', () => {
expect(sayHi()).toBe('Hello, index!');
});
});
8 changes: 8 additions & 0 deletions e2e/filter/fixtures-related/other.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { describe, expect, it } from '@rstest/core';
import { sayBye } from './src/other';

describe('other', () => {
it('should greet other', () => {
expect(sayBye()).toBe('Hello, other!');
});
});
1 change: 1 addition & 0 deletions e2e/filter/fixtures-related/src/fallback.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const fallback = () => 'fallback';
6 changes: 6 additions & 0 deletions e2e/filter/fixtures-related/src/fallback.ts.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { expect, it } from '@rstest/core';
import { unrelated } from './unrelated';

it('should not be selected by substring-only fallback matching', () => {
expect(unrelated()).toBe('unrelated');
});
3 changes: 3 additions & 0 deletions e2e/filter/fixtures-related/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { greet } from './shared';

export const sayHi = () => greet('index');
3 changes: 3 additions & 0 deletions e2e/filter/fixtures-related/src/other.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { greet } from './shared';

export const sayBye = () => greet('other');
1 change: 1 addition & 0 deletions e2e/filter/fixtures-related/src/shared.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const greet = (name: string) => `Hello, ${name}!`;
1 change: 1 addition & 0 deletions e2e/filter/fixtures-related/src/unrelated.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const unrelated = () => 'unrelated';
Loading
Loading