[Feature]: Extend the "--only-changed" to include sub imports
🚀 Feature Request
Currently, the --only-changed CLI option will detect the specs that include files that have been impacted by a change (like a file in a utils folder).
It would be awesome if the option were able to include the specs that rely on "sub-imports" (like imports of files in a fixture)
[!NOTE]
Given the current implementation, it's expected that this scenario is not working (well)
Example
Architecture (based on the POM pattern):
- tests
- pages
- fixtures
- specs
Page
export class BasePage {
// some stuff
constructor() {
// some initialisations
}
async clearInputWithText(name: string) {
await this.page.getByRole('textbox', { name }).clear()
// A NEW CHANGE TO BE DETECTED
}
}
Fixture
import { test } from '@playwright/test'
import { BasePage } from '../pages/BasePage'
export const basePageFixture = test.extend<{
basePage: BasePage
}>({
basePage: async ({ page }, use) => {
await use(new BasePage(page))
},
})
Spec
import { baseTest } from '../fixtures'
test.beforeEach(async ({ authentication, account, page }) => {
// Some stuff
})
test(
'Simple spec,
async ({ basePage }) => {
// some actions
await basePage.clearInputWithText('My awesome input')
}
)
Motivation
We currently have an architecture like the one above in the example section.
Most of our methods are under a specific page, which is imported in a fixture that will be imported only in the specs that need that page (FYI, we also have some fixtures based on mergeTests when multiple pages are needed).
If I update one of these methods (like the comment // A NEW CHANGE TO BE DETECTED), the --only-changed option is not detecting all the specs that are using that method, which is available in the spec via the fixture.
TBH, I'm not sure if it's possible to support a scenario like this, but it would help us a lot 🙏🏽
@elgorditosalsero Are you sure your changed files are not gitignore'd? I think --only-changed implementation should pick them up. At least, I cannot repro this. Could you please share a full self-contained repro, instead of some file pieces? Otherwise, we won't be able to help you, unfortunately. Take a look at this guide for helpful tips.
@elgorditosalsero Are you sure your changed files are not gitignore'd? I think
--only-changedimplementation should pick them up. At least, I cannot repro this. Could you please share a full self-contained repro, instead of some file pieces? Otherwise, we won't be able to help you, unfortunately. Take a look at this guide for helpful tips.
👋🏽 @dgozman
Thank you for the insights!
Yep, I'm pretty sure these files are not gitignored 'cause they are all specs
As you can see from the above screenshot, I've updated the DashboardBuilderPage file (in the renameDashboard method), and that file is imported in the relative fixture, and there are a bunch of files importing it...
But when running the command, only one single spec is run😕
I'm pasting also what the test:changed:local command is 🙏🏽
[!NOTE]
I'll try to reproduce this issue in a new repo so you can take a look, I hope I'll be able to share something by the end of the week 🙏🏽
👋🏽 @dgozman
Thank you for your help!
While trying to reproduce the issue in a brand new repository, I've discovered that it's not indeed an issue in the command, but on how we were importing stuff.
I've performed a bit of refactoring on the imports, removing some barrel files and some circular dependencies, and now it works like a charm!