Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lab/pact v2 #4470

Draft
wants to merge 13 commits into
base: master
Choose a base branch
from
853 changes: 837 additions & 16 deletions package-lock.json

Large diffs are not rendered by default.

13 changes: 10 additions & 3 deletions packages/atomic/playwright-utils/base-page-object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,20 @@ export class BasePageObject<
async load({
args,
story = 'default',
}: {args?: Component; story?: string} = {}) {
queryParams = {},
}: {
args?: Component;
story?: string;
queryParams?: Record<string, string>;
} = {}) {
if (args) {
await this.page.goto(
`${this.urlRoot}?id=${this.tag}--${story}&args=${buildArgsParam(undefined, this.camelToKebab(args))}`
`${this.urlRoot}?id=${this.tag}--${story}&args=${buildArgsParam(undefined, this.camelToKebab(args))}&${new URLSearchParams(queryParams).toString()}`
);
} else {
await this.page.goto(`${this.urlRoot}?id=${this.tag}--${story}`);
await this.page.goto(
`${this.urlRoot}?id=${this.tag}--${story}&${new URLSearchParams(queryParams).toString()}`
);
}
}

Expand Down
28 changes: 21 additions & 7 deletions packages/atomic/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
import {defineConfig, devices} from '@playwright/test';
import {resolve} from 'node:path';

const DEFAULT_DESKTOP_VIEWPORT = {
width: 1920,
height: 1080,
};

const pactDirectory = resolve(
import.meta.dirname,
'../headless/pact-provider/pacts'
);

export default defineConfig({
testDir: './src',
testMatch: '*.e2e.ts',
fullyParallel: true,
forbidOnly: !!process.env.CI,
forbidOnly: !!process.env.CI && false, //temp
retries: process.env.CI ? 2 : 0,
workers: process.env.CI ? 1 : undefined,
reporter: process.env.CI
Expand Down Expand Up @@ -39,11 +45,19 @@ export default defineConfig({
timeout: 7 * 1000,
},
webServer: process.env.CI
? {
command: 'npx http-server ./dist-storybook -p 4400',
port: 4400,
timeout: 120 * 1000,
reuseExistingServer: !process.env.CI,
}
? [
{
command: 'npx http-server ./dist-storybook -p 4400',
port: 4400,
timeout: 120 * 1000,
reuseExistingServer: !process.env.CI,
},
{
command: `docker run -t -p 1234:1234 -v "${pactDirectory}/:/app/pacts" pactfoundation/pact-stub-server -p 1234 -d pacts -o`,
port: 1234,
timeout: 60 * 10 * 1000,
reuseExistingServer: !process.env.CI,
},
]
: undefined,
});
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ import {test, expect} from './fixture';

test.describe('default', () => {
test.beforeEach(async ({searchBox}) => {
await searchBox.load({args: {suggestionTimeout: 5000}});
await searchBox.load({
args: {suggestionTimeout: 5000},
queryParams: {
searchProxyUrl: encodeURIComponent('http://localhost:1234'),
},
});
});

test('should have an enabled search button', async ({searchBox}) => {
Expand All @@ -21,7 +26,7 @@ test.describe('default', () => {
await searchBox.searchInput.click();
});

test('should display suggested queries', async ({searchBox}) => {
test.only('should display suggested queries', async ({searchBox}) => {
await expect(searchBox.searchSuggestions().first()).toBeVisible();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,17 @@ export const wrapInSearchInterface = (
'root-interface'
);
await step('Render the Search Interface', async () => {
await searchInterface!.initialize({
const engineConfig = {
...getSampleSearchEngineConfiguration(),
...config,
});
};
const proxyUrl = new URL(
searchInterface.ownerDocument.location.href
).searchParams.get('searchProxyUrl');
if (proxyUrl) {
engineConfig.search!.proxyBaseUrl = decodeURIComponent(proxyUrl);
}
await searchInterface!.initialize(engineConfig);
});
if (skipFirstSearch) {
return;
Expand Down
11 changes: 6 additions & 5 deletions packages/bueno/src/values/string-value.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ interface StringValueConfig<T extends string> extends ValueConfig<T> {
ISODate?: boolean;
}

// Source: https://github.com/jquery-validation/jquery-validation/blob/c1db10a34c0847c28a5bd30e3ee1117e137ca834/src/core.js#L1349
const urlRegex =
/^(?:(?:(?:https?|ftp):)?\/\/)(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})).?)(?::\d{2,5})?(?:[/?#]\S*)?$/i;
const ISODateStringRegex =
/^\d{4}(-\d\d(-\d\d(T\d\d:\d\d(:\d\d)?(\.\d+)?(([+-]\d\d:\d\d)|Z)?)?)?)?$/i;

Expand Down Expand Up @@ -48,8 +45,12 @@ export class StringValue<T extends string = string>
return 'value is an empty string.';
}

if (url && !urlRegex.test(value)) {
return 'value is not a valid URL.';
if (url) {
try {
new URL(value);
} catch (error) {
return 'value is not a valid URL.';
}
}

if (regex && !regex.test(value)) {
Expand Down
3 changes: 1 addition & 2 deletions packages/bueno/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
"esModuleInterop": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"isolatedModules": true,
"types": []
"isolatedModules": true
},
"include": ["src"],
"exclude": ["**/*.test.ts"]
Expand Down
1 change: 0 additions & 1 deletion packages/bueno/tsconfig.test.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {"types": ["jest"]},
"exclude": []
}
1 change: 1 addition & 0 deletions packages/headless/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@
"@microsoft/api-extractor": "7.47.3",
"@microsoft/api-extractor-model": "7.29.3",
"@microsoft/tsdoc": "0.15.0",
"@pact-foundation/pact": "13.1.3",
"esbuild-plugin-alias-path": "2.0.2",
"eslint-plugin-canonical": "4.18.0",
"execa": "8.0.1",
Expand Down
19 changes: 19 additions & 0 deletions packages/headless/pact-provider/commons/actionHistoryMatcher.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import {MatchersV3} from '@pact-foundation/pact';
import {iso8601Matcher} from './timeMatchers.js';

const actionHistoryQueryMatcher = {
name: 'Query',
time: iso8601Matcher,
value: MatchersV3.string(),
};

const actionHistoryPageViewMatcher = {
name: 'PageView',
time: iso8601Matcher,
value: MatchersV3.string(),
};

export const actionsHistoryMatchers = MatchersV3.eachLike(
[actionHistoryQueryMatcher, actionHistoryPageViewMatcher],
0
);
14 changes: 14 additions & 0 deletions packages/headless/pact-provider/commons/analyticsMatcher.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import {MatchersV3} from '@pact-foundation/pact';
import {iso8601Matcher} from './timeMatchers.js';

export const analyticsMatcher = {
clientId: MatchersV3.uuid('7e1ca7a0-b049-45cd-8f25-54bbb6722ea7'),
clientTimestamp: iso8601Matcher,
documentReferrer: MatchersV3.string(),
documentLocation: MatchersV3.string(),
originContext: 'Search',
capture: true,
source: MatchersV3.arrayContaining(
MatchersV3.regex(/@coveo\/headless@\d+.\d+.\d+/, '@coveo/[email protected]')
),
};
6 changes: 6 additions & 0 deletions packages/headless/pact-provider/commons/timeMatchers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import {MatchersV3} from '@pact-foundation/pact';

export const iso8601Matcher = MatchersV3.timestamp(
"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'",
'2021-01-01T00:00:00.000Z'
);
Loading
Loading