mirror of https://github.com/garrytan/gstack.git
Merge branch 'pr-499' into garrytan/merge-open-prs
This commit is contained in:
commit
0dc1899aad
|
|
@ -137,7 +137,11 @@ export async function handleMetaCommand(
|
||||||
|
|
||||||
// Separate target (selector/@ref) from output path
|
// Separate target (selector/@ref) from output path
|
||||||
for (const arg of remaining) {
|
for (const arg of remaining) {
|
||||||
if (arg.startsWith('@e') || arg.startsWith('@c') || arg.startsWith('.') || arg.startsWith('#') || arg.includes('[')) {
|
// File paths containing / and ending with an image/pdf extension are never CSS selectors
|
||||||
|
const isFilePath = arg.includes('/') && /\.(png|jpe?g|webp|pdf)$/i.test(arg);
|
||||||
|
if (isFilePath) {
|
||||||
|
outputPath = arg;
|
||||||
|
} else if (arg.startsWith('@e') || arg.startsWith('@c') || arg.startsWith('.') || arg.startsWith('#') || arg.includes('[')) {
|
||||||
targetSelector = arg;
|
targetSelector = arg;
|
||||||
} else {
|
} else {
|
||||||
outputPath = arg;
|
outputPath = arg;
|
||||||
|
|
|
||||||
|
|
@ -543,6 +543,17 @@ describe('Visual', () => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('screenshot treats relative dot-slash path as file path, not CSS selector', async () => {
|
||||||
|
await handleWriteCommand('goto', [baseUrl + '/basic.html'], bm);
|
||||||
|
// ./path/to/file.png must be treated as output path, not a CSS class selector (#495)
|
||||||
|
const relPath = './browse-test-dotpath.png';
|
||||||
|
const absPath = path.resolve(relPath);
|
||||||
|
const result = await handleMetaCommand('screenshot', [relPath], bm, async () => {});
|
||||||
|
expect(result).toContain('Screenshot saved');
|
||||||
|
expect(fs.existsSync(absPath)).toBe(true);
|
||||||
|
fs.unlinkSync(absPath);
|
||||||
|
});
|
||||||
|
|
||||||
test('screenshot with nonexistent selector throws timeout', async () => {
|
test('screenshot with nonexistent selector throws timeout', async () => {
|
||||||
await handleWriteCommand('goto', [baseUrl + '/basic.html'], bm);
|
await handleWriteCommand('goto', [baseUrl + '/basic.html'], bm);
|
||||||
try {
|
try {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue