Skip to content

Commit c37a543

Browse files
committed
fix(create): update tsconfig paths and e2e tests
1 parent e6b0665 commit c37a543

File tree

2 files changed

+23
-19
lines changed

2 files changed

+23
-19
lines changed

tools/create-element/generator/element.ts

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ const getComponentAbsPath =
111111
* If no scope is provided, returns the empty string.
112112
*/
113113
const normalizeScope = (scope: string): string =>
114-
scope ? `@${scope.replace(/^@(.*)\/$/, '$1')}/` : '';
114+
scope ? `@${scope.replace(/^(@+)(.*)\/$/, '$2')}/` : '';
115115

116116
/** Get template interpolation data from options */
117117
const getInterpolations =
@@ -121,7 +121,7 @@ const getInterpolations =
121121
const className = Case.pascal(options.tagName);
122122
const readmeName = Case.title(options.tagName.replace(/^\w+-(.*)/, '$1'));
123123
const scope = !options.scope ? '' : normalizeScope(options.scope);
124-
const packageName = `${scope}${tagName}`;
124+
const packageName = `${scope}${tagName}`.replace(/^@+/, '@');
125125
return {
126126
className,
127127
cssName,
@@ -219,17 +219,27 @@ async function updateTsconfig(options: GenerateElementOptions): Promise<void> {
219219
const configPath = join(process.cwd(), 'tsconfig.settings.json');
220220
const { packageName, tagName } = getInterpolations(options);
221221
const config = await readJson<Tsconfig>(configPath);
222-
if (!config?.compilerOptions?.paths) {
223-
return;
222+
223+
if (config?.compilerOptions?.paths) {
224+
config.compilerOptions.paths[packageName] = [join(`./elements/${tagName}/${tagName}.ts`)];
224225
}
225-
config.compilerOptions.paths[packageName] = [join(`./elements/${tagName}/${tagName}.ts`)];
226-
if (!config.references.some(x => x.path === `./elements/${tagName}`)) {
226+
227+
if (!config.references?.some(x => x.path === `./elements/${tagName}`)) {
227228
config.references.push({ 'path': `./elements/${tagName}` });
228229
}
230+
229231
await writeFile(configPath, JSON.stringify(config, null, 2), 'utf8');
230232
await execaCommand(`npx eslint --fix ${configPath}`);
231233
}
232234

235+
async function updateDocsBundle(options: GenerateElementOptions): Promise<void> {
236+
const pathname = join(process.cwd(), 'docs', 'demo', 'bundle.ts');
237+
const content = await readFile(pathname, 'utf8');
238+
239+
await writeFile(pathname, `${content}\nimport '@patternfly/${options.tagName}';`, 'utf8');
240+
await execaCommand(`npx eslint --fix ${pathname}`);
241+
}
242+
233243
/**
234244
* Generate an Element
235245
*/
@@ -246,5 +256,7 @@ export async function generateElement(options: GenerateElementOptions): Promise<
246256
await writeElementFiles(options);
247257
await analyzeElement(options);
248258
await updateTsconfig(options);
259+
await updateDocsBundle(options);
260+
await execaCommand('npm install');
249261
}
250262
}
Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,12 @@
1-
import type { LitElement } from 'lit';
2-
3-
import { expect } from '@playwright/test';
4-
import { test } from '@patternfly/pfe-tools/test/playwright/fixtures.js';
1+
import { test } from '@playwright/test';
2+
import { PfeDemoPage } from '@patternfly/pfe-tools/test/playwright/PfeDemoPage.js';
53

64
const tagName = '<%= tagName %>';
75

86
test.describe(tagName, () => {
9-
test.beforeEach(async ({ page }) => {
10-
await page.goto(`http://localhost:8080/demo/${tagName}/`);
11-
await page.waitForLoadState('networkidle');
12-
await page.waitForTimeout(100);
13-
await page.evaluate(async x => customElements.whenDefined(x), tagName);
14-
await page.$eval(tagName, async (el: LitElement) => el.updateComplete);
15-
});
16-
177
test('snapshot', async ({ page }) => {
18-
expect(await page.screenshot({ fullPage: true })).toMatchSnapshot(`${tagName}.png`);
8+
const componentPage = new PfeDemoPage(page, tagName);
9+
await componentPage.navigate();
10+
await componentPage.snapshot();
1911
});
2012
});

0 commit comments

Comments
 (0)