playwright
Advanced tools
Comparing version 1.50.0-alpha-2024-12-10 to 1.50.0-alpha-2024-12-11
@@ -8,3 +8,2 @@ "use strict"; | ||
var _matcherHint = require("./matcherHint"); | ||
var _utilsBundle = require("playwright-core/lib/utilsBundle"); | ||
var _expectBundle = require("../common/expectBundle"); | ||
@@ -15,2 +14,5 @@ var _util = require("../util"); | ||
var _utils = require("playwright-core/lib/utils"); | ||
var _fs = _interopRequireDefault(require("fs")); | ||
var _path = _interopRequireDefault(require("path")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
/** | ||
@@ -32,3 +34,3 @@ * Copyright Microsoft Corporation. All rights reserved. | ||
async function toMatchAriaSnapshot(receiver, expected, options = {}) { | ||
async function toMatchAriaSnapshot(receiver, expectedParam, options = {}) { | ||
var _options$timeout; | ||
@@ -42,3 +44,3 @@ const matcherName = 'toMatchAriaSnapshot'; | ||
name: 'toMatchAriaSnapshot', | ||
expected | ||
expected: '' | ||
}; | ||
@@ -50,4 +52,23 @@ const updateSnapshots = testInfo.config.updateSnapshots; | ||
}; | ||
if (typeof expected !== 'string') { | ||
throw new Error([(0, _matcherHint.matcherHint)(this, receiver, matcherName, receiver, expected, matcherOptions), `${_utilsBundle.colors.bold('Matcher error')}: ${(0, _expectBundle.EXPECTED_COLOR)('expected')} value must be a string`, this.utils.printWithType('Expected', expected, this.utils.printExpected)].join('\n\n')); | ||
let expected; | ||
let expectedPath; | ||
if ((0, _utils.isString)(expectedParam)) { | ||
expected = expectedParam; | ||
} else { | ||
if (expectedParam !== null && expectedParam !== void 0 && expectedParam.path) { | ||
expectedPath = expectedParam.path; | ||
} else if (expectedParam !== null && expectedParam !== void 0 && expectedParam.name) { | ||
expectedPath = testInfo.snapshotPath((0, _util.sanitizeFilePathBeforeExtension)(expectedParam.name)); | ||
} else { | ||
let snapshotNames = testInfo[snapshotNamesSymbol]; | ||
if (!snapshotNames) { | ||
snapshotNames = { | ||
anonymousSnapshotIndex: 0 | ||
}; | ||
testInfo[snapshotNamesSymbol] = snapshotNames; | ||
} | ||
const fullTitleWithoutSpec = [...testInfo.titlePath.slice(1), ++snapshotNames.anonymousSnapshotIndex].join(' '); | ||
expectedPath = testInfo.snapshotPath((0, _utils.sanitizeForFilePath)((0, _util.trimLongString)(fullTitleWithoutSpec)) + '.yml'); | ||
} | ||
expected = await _fs.default.promises.readFile(expectedPath, 'utf8').catch(() => ''); | ||
} | ||
@@ -105,9 +126,31 @@ const generateMissingBaseline = updateSnapshots === 'missing' && !expected; | ||
if (updateSnapshots === 'all' || updateSnapshots === 'changed' && pass === this.isNot || generateMissingBaseline) { | ||
const suggestedRebaseline = `toMatchAriaSnapshot(\`\n${(0, _utils.escapeTemplateString)(indent(typedReceived.regex, '{indent} '))}\n{indent}\`)`; | ||
return { | ||
pass: this.isNot, | ||
message: () => '', | ||
name: 'toMatchAriaSnapshot', | ||
suggestedRebaseline | ||
}; | ||
if (expectedPath) { | ||
await _fs.default.promises.mkdir(_path.default.dirname(expectedPath), { | ||
recursive: true | ||
}); | ||
await _fs.default.promises.writeFile(expectedPath, typedReceived.regex, 'utf8'); | ||
const relativePath = _path.default.relative(process.cwd(), expectedPath); | ||
if (updateSnapshots === 'missing') { | ||
const message = `A snapshot doesn't exist at ${relativePath}, writing actual.`; | ||
testInfo._hasNonRetriableError = true; | ||
testInfo._failWithError(new Error(message)); | ||
} else { | ||
const message = `A snapshot is generated at ${relativePath}.`; | ||
/* eslint-disable no-console */ | ||
console.log(message); | ||
} | ||
return { | ||
pass: true, | ||
message: () => '', | ||
name: 'toMatchAriaSnapshot' | ||
}; | ||
} else { | ||
const suggestedRebaseline = `toMatchAriaSnapshot(\`\n${(0, _utils.escapeTemplateString)(indent(typedReceived.regex, '{indent} '))}\n{indent}\`)`; | ||
return { | ||
pass: false, | ||
message: () => '', | ||
name: 'toMatchAriaSnapshot', | ||
suggestedRebaseline | ||
}; | ||
} | ||
} | ||
@@ -137,2 +180,3 @@ } | ||
return snapshot.split('\n').map(line => indent + line).join('\n'); | ||
} | ||
} | ||
const snapshotNamesSymbol = Symbol('snapshotNames'); |
{ | ||
"name": "playwright", | ||
"version": "1.50.0-alpha-2024-12-10", | ||
"version": "1.50.0-alpha-2024-12-11", | ||
"description": "A high-level API to automate web browsers", | ||
@@ -59,3 +59,3 @@ "repository": { | ||
"dependencies": { | ||
"playwright-core": "1.50.0-alpha-2024-12-10" | ||
"playwright-core": "1.50.0-alpha-2024-12-11" | ||
}, | ||
@@ -62,0 +62,0 @@ "optionalDependencies": { |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3157563
35848
177
+ Addedplaywright-core@1.50.0-alpha-2024-12-11(transitive)
- Removedplaywright-core@1.50.0-alpha-2024-12-10(transitive)