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

fix: correctly define screenshotsDir option for browsers #1060

Merged
merged 1 commit into from
Feb 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions src/config/browser-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,14 +189,19 @@ function buildBrowserOptions(defaultFactory, extra) {
throw new Error('"screenshotsDir" must be a string or function');
}
},
map: (value, _, __, { isSetByUser }) => {
const deprecatedScreensPath = "hermione/screens";
map: (value, config, __, { isSetByUser }) => {
if (isSetByUser) {
return value;
}

if (!isSetByUser && fs.existsSync(deprecatedScreensPath) && !fs.existsSync(value)) {
return deprecatedScreensPath;
const topLevelScreenshotsDir = _.get(config, "screenshotsDir");
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for top level option this will be undefined because option is not set. But when parse browser this option will have value from top level. And will be used if user not set it specially for browser

if (topLevelScreenshotsDir) {
return topLevelScreenshotsDir;
}

return value;
const deprecatedScreensPath = "hermione/screens";

return fs.existsSync(deprecatedScreensPath) && !fs.existsSync(value) ? deprecatedScreensPath : value;
},
}),

Expand Down
29 changes: 25 additions & 4 deletions test/src/config/browser-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,11 @@ describe("config browser-options", () => {
});

it("should fallback default value to hermione/screens, if it exists and default dir not exists", () => {
const readConfig = {};
const readConfig = {
browsers: {
b1: mkBrowser_(),
},
};
Config.read.returns(readConfig);
sandbox
.stub(fs, "existsSync")
Expand All @@ -543,10 +547,15 @@ describe("config browser-options", () => {
const config = createConfig();

assert.equal(config.screenshotsDir, "hermione/screens");
assert.equal(config.browsers.b1.screenshotsDir, "hermione/screens");
});

it("should use default testplane/screens if both hermione/screens and testplane/screens exists", () => {
const readConfig = {};
const readConfig = {
browsers: {
b1: mkBrowser_(),
},
};
Config.read.returns(readConfig);
sandbox
.stub(fs, "existsSync")
Expand All @@ -558,10 +567,15 @@ describe("config browser-options", () => {
const config = createConfig();

assert.equal(config.screenshotsDir, "testplane/screens");
assert.equal(config.browsers.b1.screenshotsDir, "testplane/screens");
});

it("should not fallback default value to hermione/screens, if not exists", () => {
const readConfig = {};
const readConfig = {
browsers: {
b1: mkBrowser_(),
},
};
Config.read.returns(readConfig);
sandbox
.stub(fs, "existsSync")
Expand All @@ -573,10 +587,16 @@ describe("config browser-options", () => {
const config = createConfig();

assert.equal(config.screenshotsDir, "testplane/screens");
assert.equal(config.browsers.b1.screenshotsDir, "testplane/screens");
});

it("should not fallback value to hermione/screens, if defined", () => {
const readConfig = { screenshotsDir: "some/dir" };
const readConfig = {
screenshotsDir: "some/dir",
browsers: {
b1: mkBrowser_({ screenshotsDir: "another/dir" }),
},
};
Config.read.returns(readConfig);
sandbox
.stub(fs, "existsSync")
Expand All @@ -588,6 +608,7 @@ describe("config browser-options", () => {
const config = createConfig();

assert.equal(config.screenshotsDir, "some/dir");
assert.equal(config.browsers.b1.screenshotsDir, "another/dir");
});
});

Expand Down