Skip to content

Commit

Permalink
simple-addon-dsl (#80)
Browse files Browse the repository at this point in the history
fix playwright tests
  • Loading branch information
lifeart authored Dec 9, 2023
1 parent c10be82 commit 7356ef4
Show file tree
Hide file tree
Showing 10 changed files with 551 additions and 428 deletions.
2 changes: 2 additions & 0 deletions e2e/flows/404.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { test, expect } from '@playwright/test';

import { captureCoverage } from './../utils/index.ts';
import { skipModalDialog } from './../utils/modal-dialog.ts';

captureCoverage(test);

test.describe('NotFound route', () => {
test('it loadable', async ({ page }) => {
await page.goto('http://localhost:4200/foo-bar-baz');
await skipModalDialog(page);
// Expect a title "to contain" a substring.
await expect(page).toHaveTitle(/Not found/);
// Expect an element "to contain" text.
Expand Down
3 changes: 3 additions & 0 deletions e2e/flows/bootstrap-navigation.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { test, expect } from '@playwright/test';

import { captureCoverage } from './../utils/index.ts';
import { skipModalDialog } from './../utils/modal-dialog.ts';


captureCoverage(test);

test.describe('Ember-Bootstrap route', () => {
test('it loadable', async ({ page }) => {
await page.goto('http://localhost:4200');
await skipModalDialog(page);
await expect(page).not.toHaveTitle(/Bootstrap/);
await page.click('a[href="/bootstrap"]');
// Expect a title "to contain" a substring.
Expand Down
5 changes: 5 additions & 0 deletions e2e/flows/happy-path.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { test, expect } from '@playwright/test';

import { captureCoverage } from './../utils/index.ts';
import { skipModalDialog } from './../utils/modal-dialog.ts';

captureCoverage(test);

test.describe('Happy path', () => {
test('i11n is working just fine', async ({ page }) => {
await page.goto('http://localhost:4200');
await skipModalDialog(page);

const msgNode = page.locator('[data-test-welcome-msg]');

Expand Down Expand Up @@ -35,6 +37,7 @@ test.describe('Happy path', () => {

test('dialog click is working fine', async ({ page }) => {
await page.goto('http://localhost:4200');
await skipModalDialog(page);

page.on('dialog', (dialog) => {
expect(dialog.message()).toBe('Fine');
Expand All @@ -45,6 +48,7 @@ test.describe('Happy path', () => {

test('power select is working fine', async ({ page }) => {
await page.goto('http://localhost:4200');
await skipModalDialog(page);

await expect(
page.locator('.ember-power-select-trigger'),
Expand All @@ -71,6 +75,7 @@ test.describe('Happy path', () => {

test('timer is working fine', async ({ page }) => {
await page.goto('http://localhost:4200');
await skipModalDialog(page);

const t1 = await page.locator('pre.font-mono').textContent();
// eslint-disable-next-line playwright/no-wait-for-timeout
Expand Down
5 changes: 5 additions & 0 deletions e2e/flows/login.spec.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
import { test, expect } from '@playwright/test';

import { captureCoverage } from './../utils/index.ts';
import { skipModalDialog } from './../utils/modal-dialog.ts';

captureCoverage(test);

test.describe('login flow', () => {
test('by default user is logged out', async ({ page }) => {
await page.goto('http://localhost:4200');
await skipModalDialog(page);
await expect(page.locator('[data-login-status]')).toContainText(
'You are not authenticated'
);
});
test('user could not visit profile page if logged out', async ({ page }) => {
await page.goto('http://localhost:4200/profile');
await skipModalDialog(page);
await page.click('a[href="/profile"]');
await expect(page.url()).toBe('http://localhost:4200/login');
});
test('user could use login form', async ({ page }) => {
await page.goto('http://localhost:4200/login');
await skipModalDialog(page);
await page.click('[data-test-login-button]');
await page.waitForURL('http://localhost:4200/profile');

Expand All @@ -31,6 +35,7 @@ test.describe('login flow', () => {
});
test('user could logout', async ({ page }) => {
await page.goto('http://localhost:4200/profile');
await skipModalDialog(page);
await page.click('[data-test-login-button]');
await page.waitForURL('http://localhost:4200/profile');
await expect(page.url()).toBe('http://localhost:4200/profile');
Expand Down
6 changes: 6 additions & 0 deletions e2e/utils/modal-dialog.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import type { Page } from '@playwright/test';

export async function skipModalDialog(page: Page) {
await page.click('[data-test-id="close-modal-dialog"]');
await new Promise((resolve) => setTimeout(resolve, 500));
}
2 changes: 1 addition & 1 deletion playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export default defineConfig({
/* Run your local dev server before starting the tests */
webServer: {
command: 'yarn dev',
url: 'http://127.0.0.1:4200',
url: 'http://localhost:4200',
reuseExistingServer: !process.env.CI,
},
});
132 changes: 132 additions & 0 deletions plugins/ember-vendor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
import fs from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { Addon, compatPath, nodePath } from './ember';

const self = import.meta.url;

const modeModulesPath = path.resolve(
path.dirname(fileURLToPath(self)),
'./../node_modules'
);

export function internalPackages(mode: string) {
return [
Addon('ember & ember-source & @ember/*', mode)
.addAlias(/^ember$/, 'ember-source/dist/packages/ember')
.addAlias(/^ember\/version$/, 'ember-source/dist/packages/ember/version')
.addAliases(
emberPackages().map((pkg) => ({
find: `@ember/${pkg}`,
replacement: nodePath(`ember-source/dist/packages/@ember/${pkg}`),
}))
),

Addon('@glimmer/*', mode)
.addAlias(
'@glimmer/validator',
nodePath('@glimmer/validator/dist/modules/es2017')
)
.addAlias(
'@glimmer/tracking/primitives/cache',
nodePath(
`ember-source/dist/packages/@glimmer/tracking/primitives/cache.js`
)
)
.addAlias(
/@glimmer\/tracking$/,
nodePath(`ember-source/dist/packages/@glimmer/tracking`)
)
.addAlias(
'@glimmer/component',
'@glimmer/component/addon/-private/component'
)
.addAlias('@glimmer/env', compatPath('glimmer-env'))
.addAliases(
emberGlimmerDepsPackages().map((pkg) => ({
find: `@glimmer/${pkg}`,
replacement: nodePath(
`ember-source/dist/dependencies/@glimmer/${pkg}`
),
}))
),

Addon('backburner', mode).addAlias(
/^backburner$/,
nodePath('backburner.js/dist/es6/backburner.js')
),

Addon('ember-component-manager', mode).addSelfAlias(
'@glimmer/component/addon/-private/ember-component-manager'
),

Addon('@ember/test-helpers', mode).addSelfAlias(
'@ember/test-helpers/addon-test-support/@ember/test-helpers'
),

Addon('@ember/test-waiters', mode).addSelfAlias(
'@ember/test-waiters/addon/@ember/test-waiters'
),

Addon('ember-compatibility-helpers', mode).addSelfAlias(
compatPath('ember-compatibility-helpers/index.ts')
),
Addon('ember-cli-htmlbars', mode).addSelfAlias(
compatPath('ember-cli-htmlbars/index.ts')
),
Addon('ember-cli-test-loader', mode).addNestedAlias(
'test-support/index',
compatPath('ember-cli-test-loader/index.ts')
),
Addon('ember-cli-version-checker', mode).addSelfAlias(
compatPath('ember-cli-version-checker/index.ts')
),
Addon('compat-ember-decorators', mode).addNestedAlias(
'component',
compatPath('ember-decorators/component.ts')
),
Addon('require', mode).addSelfAlias(compatPath('require/index.ts')),
Addon('ember-template-compiler', mode).addSelfAlias(
'node_modules/ember-source/dist/ember-template-compiler.js'
),
Addon('ember-testing', mode)
.addAlias(/^ember-testing$/, 'ember-source/dist/packages/ember-testing')
.addAlias(
/^ember-testing\//,
'ember-source/dist/packages/ember-testing/'
),
Addon('@embroider/macros', mode).addSelfAlias(
compatPath('embroider-macros/index.ts')
),
Addon('@embroider/util', mode).addSelfAlias(
compatPath('embroider-util/index.ts')
),
Addon('@ember/string', mode).needAlias(),
];
}

export function emberGlimmerDepsPackages() {
return fs
.readdirSync(
path.join(
modeModulesPath,
'ember-source',
'dist',
'dependencies',
'@glimmer'
)
)
.filter((el) => !el.includes('env.') && !el.includes('manager.'))
.map((el) => el.replace('.js', ''));
}

export function emberPackages() {
return fs.readdirSync(
path.join(modeModulesPath, 'ember-source', 'dist', 'packages', '@ember')
);
}

export function eDataPackages() {
const els = fs.readdirSync(path.join(modeModulesPath, '@ember-data'));
return els.filter((e) => e !== 'private-build-infra');
}
Loading

0 comments on commit 7356ef4

Please sign in to comment.