Skip to content
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,58 @@ jobs:
parallel: true
fail-on-error: false

e2e:
name: Browser E2E (Chromium)
runs-on: ubuntu-latest
needs:
- build

steps:
- name: git checkout
uses: actions/checkout@v4

- name: Use Node.js 22.x
uses: actions/setup-node@v4
with:
node-version: 22.x
cache: 'npm'

- name: Install dependencies
run: npm ci

- name: Build packages and browser bundles
run: npm run build

- name: Get Playwright version
id: playwright-version
run: echo "version=$(node -p 'require(\"@playwright/test/package.json\").version')" >> "$GITHUB_OUTPUT"

- name: Cache Playwright browsers
id: playwright-cache
uses: actions/cache@v4
with:
path: ~/.cache/ms-playwright
key: playwright-${{ runner.os }}-${{ steps.playwright-version.outputs.version }}

- name: Install Playwright Chromium
if: steps.playwright-cache.outputs.cache-hit != 'true'
run: npx playwright install --with-deps chromium

- name: Install Playwright system deps only (cache hit)
if: steps.playwright-cache.outputs.cache-hit == 'true'
run: npx playwright install-deps chromium

- name: Run browser e2e tests
run: npx playwright test --config e2e/playwright.config.ts --reporter=list

- name: Upload Playwright report on failure
if: failure()
uses: actions/upload-artifact@v4
with:
name: playwright-report
path: e2e/playwright-report
retention-days: 7

notify:
needs:
- build
Expand Down
2 changes: 2 additions & 0 deletions DEVELOPERS.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ npm run test

> **Note:** The build step is required because some packages (like `concerto-linter`) depend on other workspace packages that need to be compiled first. The CI workflows follow this same pattern: build first, then test.

> **Note:** Always build the whole monorepo with `npm run build` (which builds in dependency order), not a single package in isolation. Because each package's `exports.import` condition resolves to its `dist/esm/index.mjs`, building one package alone can fail if a workspace dependency's ESM output does not yet exist. `npm run build:ordered` (the default `build` script) handles this ordering; CI relies on it too.

If you're working on a specific package, you can run tests for just that package:

```shell
Expand Down
4 changes: 4 additions & 0 deletions e2e/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules/
test-results/
playwright-report/
playwright/.cache/
13 changes: 13 additions & 0 deletions e2e/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "concerto-e2e",
"version": "1.0.0",
"private": true,
"description": "End-to-end browser tests for Concerto web bundles.",
"scripts": {
"pretest:e2e": "npm --prefix .. run build",
"test:e2e": "playwright test"
},
"devDependencies": {
"@playwright/test": "^1.60.0"
}
}
30 changes: 30 additions & 0 deletions e2e/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { defineConfig, devices } from '@playwright/test';

export default defineConfig({
testDir: './tests',
fullyParallel: true,
forbidOnly: !!process.env.CI,
retries: process.env.CI ? 1 : 0,
workers: process.env.CI ? 1 : undefined,
reporter: 'list',
use: {
trace: 'on-first-retry',
},
projects: [
{ name: 'chromium', use: { ...devices['Desktop Chrome'] } },
],
});
86 changes: 86 additions & 0 deletions e2e/tests/browser-bundles.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { test, expect, Page } from '@playwright/test';
import * as path from 'path';
Comment thread
mttrbrts marked this conversation as resolved.
Resolved

const CTO_BUNDLE = path.resolve(__dirname, '../../packages/concerto-cto/dist/concerto-cto.js');
const CORE_BUNDLE = path.resolve(__dirname, '../../packages/concerto-core/dist/concerto-core.js');

async function injectBundle(page: Page, bundlePath: string): Promise<void> {
await page.goto('about:blank');
await page.addScriptTag({ path: bundlePath });
}

test.describe('Concerto browser bundles', () => {
test('loads the CTO parser UMD bundle in Chromium', async ({ page }) => {
await injectBundle(page, CTO_BUNDLE);

const parsed = await page.evaluate(() => {
const { Parser } = (window as any)['concerto-cto'];
const ast = Parser.parse('namespace org.acme.test@1.0.0\nconcept Person { o String name }');
return {
namespace: ast.namespace,
declarationCount: ast.declarations.length,
};
});

expect(parsed).toEqual({
namespace: 'org.acme.test@1.0.0',
declarationCount: 1,
});
});

test('loads the core UMD bundle and uses ModelManager in Chromium', async ({ page }) => {
await injectBundle(page, CORE_BUNDLE);

const model = await page.evaluate(() => {
const { ModelManager } = (window as any)['concerto-core'];
const modelManager = new ModelManager();
modelManager.addCTOModel(
'namespace org.acme.browser@1.0.0\nasset Vehicle identified by vin { o String vin }',
'vehicle.cto',
true
);
const vehicle = modelManager.getType('org.acme.browser@1.0.0.Vehicle');
return {
fqn: vehicle.getFullyQualifiedName(),
identifierFieldName: vehicle.getIdentifierFieldName(),
};
});

expect(model).toEqual({
fqn: 'org.acme.browser@1.0.0.Vehicle',
identifierFieldName: 'vin',
});
});

test('keeps dayjs plugins available through the core bundle', async ({ page }) => {
await injectBundle(page, CORE_BUNDLE);

const currentTime = await page.evaluate(() => {
const { DateTimeUtil } = (window as any)['concerto-core'];
const result = DateTimeUtil.setCurrentTime('2023-03-17T12:30:00.000Z', 0);
return {
iso: result.currentTime.toISOString(),
offset: result.utcOffset,
};
});

expect(currentTime).toEqual({
iso: '2023-03-17T12:30:00.000Z',
offset: 0,
});
});
});
Loading
Loading