chore: add CI to default user agent (#15450)
This commit is contained in:
parent
b8deb2ba8f
commit
86a65a03e4
|
|
@ -57,9 +57,13 @@ function determineUserAgent(): string {
|
||||||
osIdentifier = 'linux';
|
osIdentifier = 'linux';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
const additionalTokens = [];
|
||||||
|
if (process.env.CI)
|
||||||
|
additionalTokens.push('CI/1');
|
||||||
|
const serializedTokens = additionalTokens.length ? ' ' + additionalTokens.join(' ') : '';
|
||||||
|
|
||||||
const { langName, langVersion } = getClientLanguage();
|
const { langName, langVersion } = getClientLanguage();
|
||||||
return `Playwright/${getPlaywrightVersion()} (${os.arch()}; ${osIdentifier} ${osVersion}) ${langName}/${langVersion}`;
|
return `Playwright/${getPlaywrightVersion()} (${os.arch()}; ${osIdentifier} ${osVersion}) ${langName}/${langVersion}${serializedTokens}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getClientLanguage(): { langName: string, langVersion: string } {
|
export function getClientLanguage(): { langName: string, langVersion: string } {
|
||||||
|
|
|
||||||
|
|
@ -189,14 +189,19 @@ it('should set playwright as user-agent', async ({ playwright, server, isWindows
|
||||||
.replace(getPlaywrightVersion(), 'X.X.X')
|
.replace(getPlaywrightVersion(), 'X.X.X')
|
||||||
.replace(/\d+/g, 'X');
|
.replace(/\d+/g, 'X');
|
||||||
|
|
||||||
|
const tokens = [];
|
||||||
|
if (process.env.CI)
|
||||||
|
tokens.push('CI/X');
|
||||||
|
const suffix = tokens.length ? ` ${tokens.join(' ')}` : '';
|
||||||
|
|
||||||
if (isWindows)
|
if (isWindows)
|
||||||
expect(userAgentMasked).toBe('Playwright/X.X.X (<ARCH>; windows X.X) node/X.X');
|
expect(userAgentMasked).toBe('Playwright/X.X.X (<ARCH>; windows X.X) node/X.X' + suffix);
|
||||||
else if (isLinux)
|
else if (isLinux)
|
||||||
// on ubuntu: distro is 'ubuntu' and version is 'X.X'
|
// on ubuntu: distro is 'ubuntu' and version is 'X.X'
|
||||||
// on manjaro: distro is 'Manjaro' and version is 'unknown'
|
// on manjaro: distro is 'Manjaro' and version is 'unknown'
|
||||||
expect(userAgentMasked.replace(/<ARCH>; \w+ [^)]+/, '<ARCH>; distro version')).toBe('Playwright/X.X.X (<ARCH>; distro version) node/X.X');
|
expect(userAgentMasked.replace(/<ARCH>; \w+ [^)]+/, '<ARCH>; distro version')).toBe('Playwright/X.X.X (<ARCH>; distro version) node/X.X' + suffix);
|
||||||
else if (isMac)
|
else if (isMac)
|
||||||
expect(userAgentMasked).toBe('Playwright/X.X.X (<ARCH>; macOS X.X) node/X.X');
|
expect(userAgentMasked).toBe('Playwright/X.X.X (<ARCH>; macOS X.X) node/X.X' + suffix);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should be able to construct with context options', async ({ playwright, browserType, server }) => {
|
it('should be able to construct with context options', async ({ playwright, browserType, server }) => {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue