Skip to content

Commit 108dd17

Browse files
committed
test(nx-payload): fix flaky e2e
1 parent 191cfcf commit 108dd17

File tree

3 files changed

+23
-36
lines changed

3 files changed

+23
-36
lines changed

e2e/nx-payload-e2e/jest.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ export default {
22
displayName: 'nx-payload-e2e',
33
preset: '../../jest.preset.js',
44
setupFilesAfterEnv: ['<rootDir>/jest.setup.ts'],
5+
testEnvironment: 'node',
56
globals: {},
67
transform: {
78
'^.+\\.[tj]s$': [

e2e/nx-payload-e2e/src/nx-payload.ui.spec.ts

Lines changed: 21 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -38,21 +38,6 @@ describe('Test user login and onboarding', () => {
3838
password: 'dev'
3939
};
4040

41-
const selectors = {
42-
header: 'h1',
43-
subHeader: 'p',
44-
adminLink: 'a[href="/admin"]',
45-
emailInput: '#field-email',
46-
nameInput: '#field-name',
47-
passwordInput: '#field-password',
48-
passwordConfirmInput: '#field-password-confirm',
49-
roleSelect: '#field-role',
50-
roleOption: 'text=admin',
51-
submitButton: '.form-submit button[type="submit"]',
52-
dashboardUserCard: '#card-users',
53-
dashboardMediaCard: '#card-media'
54-
};
55-
5641
jest.setTimeout(300_000);
5742

5843
beforeAll(async () => {
@@ -101,48 +86,49 @@ describe('Test user login and onboarding', () => {
10186
});
10287

10388
it('should have start page with hero and admin page link', async () => {
104-
await page.waitForSelector(selectors.header);
105-
expect(await page.textContent(selectors.header)).toContain('Welcome');
89+
const header = page.locator('h1');
90+
await header.waitFor();
91+
expect(await header.textContent()).toContain('Welcome');
10692

107-
await page.waitForSelector(selectors.adminLink);
108-
expect(await page.textContent(selectors.adminLink)).toContain('Admin');
93+
const adminLink = page.locator('a[href="/admin"]');
94+
await adminLink.waitFor();
95+
expect(await adminLink.textContent()).toContain('Admin');
10996
});
11097

11198
it('should navigate to admin page and login or onboard user', async () => {
112-
await page.waitForSelector(selectors.adminLink);
99+
const adminLink = page.locator('a[href="/admin"]');
100+
await adminLink.waitFor();
113101

114102
// Get admin page in the new tab after clicking the admin link
115103
const [adminPage] = await Promise.all([
116104
context.waitForEvent('page'),
117-
page.click(selectors.adminLink)
105+
adminLink.click()
118106
]);
119107
await adminPage.waitForLoadState();
120108

121-
const button = await adminPage.waitForSelector(selectors.submitButton);
109+
const button = adminPage.getByRole('button');
122110

123111
// Check if we have to onboard or login
124112
if ((await button.textContent()) === 'Login') {
125-
await adminPage.fill(selectors.emailInput, credentials.email);
126-
await adminPage.fill(selectors.passwordInput, credentials.password);
113+
await adminPage.getByLabel('Email').fill(credentials.email);
114+
await adminPage.getByLabel('Password').fill(credentials.password);
127115
} else {
128-
await adminPage.fill(selectors.nameInput, 'Admin User');
129-
await adminPage.fill(selectors.emailInput, credentials.email);
130-
await adminPage.fill(selectors.passwordInput, credentials.password);
131-
await adminPage.fill(
132-
selectors.passwordConfirmInput,
133-
credentials.password
134-
);
135-
await adminPage.locator(selectors.roleSelect).click();
136-
await adminPage.locator(selectors.roleOption).click();
116+
await adminPage.getByLabel('Name').fill('Admin User');
117+
await adminPage.getByLabel('Email').fill(credentials.email);
118+
await adminPage.getByLabel('New Password').fill(credentials.password);
119+
await adminPage.getByLabel('Confirm Password').fill(credentials.password);
120+
// It's not a proper select field, so we have to click to reveal options and then click the option
121+
await adminPage.locator('#field-role').click();
122+
await adminPage.getByRole('option', { name: 'Admin' }).click();
137123
}
138124

139125
// Submit form
140126
await button.click();
141127

142128
// Verify we reach the dashboard with Users and Media cards
143129
await Promise.all([
144-
adminPage.waitForSelector(selectors.dashboardUserCard),
145-
adminPage.waitForSelector(selectors.dashboardMediaCard)
130+
adminPage.locator('#card-users').waitFor(),
131+
adminPage.locator('#card-media').waitFor()
146132
]);
147133
});
148134
});

e2e/utils/ensure-docker-connect-to-local-registry.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,6 @@ registry=http://${registry.host}:${registry.port}
3232

3333
// `.npmrc` is normally not required in `Dockerfile`
3434
updateFile(`apps/${appName}/Dockerfile`, (content) =>
35-
content.replace(/^(COPY package\.json.*) \.\/$/, '$1 .npmrc ./')
35+
content.replace(/^COPY package\.json \.\/$/m, 'COPY .npmrc package.json ./')
3636
);
3737
};

0 commit comments

Comments
 (0)