๐ ๋ชฉ์ฐจ
- Introduction
- Setting์ ์ด๋ป๊ฒ ํด์ผํ ๊น?
- Conclusion
- Reference
๐ Introduction
์๋ ํ์ธ์ ์ด๋ฒ ํฌ์คํ ์ ์ง๋๋ฒ์ ์๋ ค๋๋ฆฐ๋๋ก BDD๋ฅผ ์ธํ ํ๋ ๋ฐฉ๋ฒ์ ๋ํด์ ์๋ ค๋๋ฆฌ๋ ค๊ณ ํฉ๋๋ค. ์ค์ ์ฝ๋๋ ์ฌ๊ธฐ๋ฅผ ์ฐธ๊ณ ํ์๋ฉด ๋ฉ๋๋ค. ๐
๐ Setting์ ํ๋ ๋ฐฉ๋ฒ
๋จผ์ cypress-cucumber-preprocessor๋ฅผ ์ค์นํด์ฃผ์ธ์
npm i -D cypress-cucumber-preprocessor
package.json
package.json
์ ํด๋น ๋ด์ฉ์ ์ถ๊ฐํด์ฃผ์ธ์.
"cypress-cucumber-preprocessor": {
"nonGlobalStepDefinitions": true,
"stepDefinitions": "tests/e2e/specs",
"commonPath": "tests/e2e/common",
"cucumberJson": {
"generate": true,
"outputFolder": "tests/e2e/cucumber-json",
"filePrefix": "",
"fileSuffix": ".cucumber"
}
cypress.json
cypress.json
์ ํด๋น ๋ด์ฉ์ ์ถ๊ฐํด์ฃผ์ธ์.
{
"baseUrl": "http://localhost:8080",
"chromeWebSecurity": false,
"testFiles": "**/*.{feature,features}"
}
cypress/plugins/index.js
cypress/plugins/index.js
์ ํด๋น ๋ด์ฉ์ ์ถ๊ฐํด์ฃผ์ธ์.
const cucumber = require("cypress-cucumber-preprocessor").default;// ์ด๋ถ๋ถ
module.exports = (on, config) => {
on("file:preprocessor", cucumber()); // ์ด๋ถ๋ถ
return Object.assign({}, config, {
fixturesFolder: "tests/e2e/fixtures",
integrationFolder: "tests/e2e/specs",
screenshotsFolder: "tests/e2e/screenshots",
videosFolder: "tests/e2e/videos",
supportFile: "tests/e2e/support/index.js",
});
};
cypress/support/commands.js
cypress/support/commands.js
์ ํด๋น ๋ด์ฉ์ ์ถ๊ฐํด์ฃผ์ธ์.
Cypress.Commands.add("the", testSelector =>
cy.get(`[data-test-${testSelector}]`)
);
Cypress.Commands.add("clickThe", testSelector => {
cy.get(`[data-test-${testSelector}]`).click();
});
Cypress.Commands.add("clickTheFirst", testSelector => {
cy.get(`[data-test-${testSelector}]`)
.eq(0)
.click();
});
Cypress.Commands.add("theFirst", testSelector =>
cy.get(`[data-test-${testSelector}]`).eq(0)
);
Cypress.Commands.add("fillOutThe", testSelector =>
cy.get(`[data-test-${testSelector}]`)
);
Cypress.Commands.add("with", { prevSubject: true }, (form, formData) => {
cy.wrap(Object.keys(formData)).each(key => {
cy.get(form)
.find(`[name=${key}]`)
.type(formData[key]);
});
cy.get(form).submit();
});
Cypress.Commands.add("getStore", () => {
return cy.window().its("app.__vue__.$store");
});
Cypress.Commands.add(
"dispatch",
{ prevSubject: true },
(store, methodToDispatch, ...dispatchArguments) => {
return store.dispatch(methodToDispatch, ...dispatchArguments);
}
);
Cypress.Commands.add(
"commit",
{ prevSubject: true },
(store, methodToCommit, ...commitArguments) => {
return store.commit(methodToCommit, ...commitArguments);
}
);
Cypress.Commands.add(
"setState",
{ prevSubject: true },
(store, property, value) => {
store.state[property] = value;
return value;
}
);
Cypress.Commands.add(
"getState",
{ prevSubject: true },
(store, property) => {
return store.state[property];
}
);
๋ง์ฝ store์ namspaced๋ฅผ ์ฌ์ฉํ๋ค๋ฉด getStore
,dispatch
,commit
,setState
,getState
๋ฅผ ์ด๋ ๊ฒ ๋ฐ๊ฟ์ฃผ์๋ฉด ๋ฉ๋๋ค.
Cypress.Commands.add("getStore", () => {
return cy.window().its("app.__vue__.$store");
});
Cypress.Commands.add(
"dispatch",
{ prevSubject: true },
(store, moduleName, methodToDispatch, ...dispatchArguments) => {
return store[moduleName].dispatch(methodToDispatch, ...dispatchArguments);
}
);
Cypress.Commands.add(
"commit",
{ prevSubject: true },
(store, moduleName, methodToCommit, ...commitArguments) => {
return store[moduleName].commit(methodToCommit, ...commitArguments);
}
);
Cypress.Commands.add(
"setState",
{ prevSubject: true },
(store, moduleName, property, value) => {
store.state[moduleName][property] = value;
return value;
}
);
Cypress.Commands.add(
"getState",
{ prevSubject: true },
(store, moduleName, property) => {
return store.state[moduleName][property];
}
);
๐ Conclusion
์ด๋ ๊ฒ ์ธํ ์ ํด์ฃผ๋ฉด ์ด์ ์ ๋ง BDD๋ฅผ ํ ์ค๋น๊ฐ ๋์์ต๋๋ค. ์ ๋ง๋ก ์ด์ ๋ค์ ํฌ์คํ ์์๋ ์ด์ ์ง์ง BDD๋ฅผ ํ๋ ๋ฐฉ๋ฒ์ ๋ํด์ ํฌ์คํ ์ ํด๋ณด๊ฒ ์ต๋๋ค.๐
๐ Reference
'Vue BDD' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
Vue BDD - Cypress Mock Api (0) | 2020.10.13 |
---|---|
Vue BDD - Cypress ์ ์ฉํ๊ธฐ (0) | 2020.10.13 |
Vue BDD - Gherkin (0) | 2020.10.06 |
Vue BDD - Intro (0) | 2020.10.05 |