Commit de749d46 authored by Egor Kremnev's avatar Egor Kremnev

add feature tests

parent 00355658
const path = require('path');
const rootPath = __dirname;
const isTest = process.env.NODE_ENV === 'test';
module.exports = {
rootPath,
port: 8010,
port: isTest ? 8010 : 8020,
uploadPath: path.join(rootPath, 'public', 'uploads'),
db: {
host: 'mongodb://127.0.0.1',
database: 'shop',
database: isTest ? 'shop-test' : 'shop',
}
};
......@@ -7,7 +7,9 @@
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node index.js",
"dev": "nodemon index.js",
"fixture": "node fixtures.js"
"seed": "node fixtures.js",
"start:test": "NODE_ENV=test node index.js",
"seed:test": "NODE_ENV=test npm run seed"
},
"keywords": [],
"author": "",
......
......@@ -26,7 +26,8 @@
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
"eject": "react-scripts eject",
"start:test": "REACT_APP_NODE_ENV=test PORT=3010 react-scripts start"
},
"eslintConfig": {
"extends": [
......
export const apiUrl = "http://localhost:8010";
const isTest = process.env.REACT_APP_NODE_ENV === 'test';
export const apiUrl = "http://localhost:" + (isTest ? 8010 : 8020);
export const uploadUrl = apiUrl + '/uploads';
.idea
.vscode
.fleet
.DS_Store
node_modules
.cache
const {join} = require('path');
/**
* @type {import("puppeteer").Configuration}
*/
module.exports = {
// Changes the cache location for Puppeteer.
cacheDirectory: join(__dirname, '.cache', 'puppeteer'),
};
exports.config = {
output: './output',
helpers: {
Puppeteer: {
url: 'http://localhost:3010',
windowSize: '1200x900'
}
},
include: {
I: './steps_file.js'
},
mocha: {},
bootstrap: null,
timeout: null,
teardown: null,
hooks: [],
gherkin: {
features: './features/*.feature',
steps: ['./step_definitions/steps.js']
},
plugins: {
screenshotOnFail: {
enabled: true
},
tryTo: {
enabled: true
},
retryFailedStep: {
enabled: false
},
retryTo: {
enabled: true
},
eachElement: {
enabled: true
},
pauseOnFail: {}
},
stepTimeout: 0,
stepTimeoutOverride: [{
pattern: 'wait.*',
timeout: 0
},
{
pattern: 'amOnPage',
timeout: 0
}
],
tests: './*_test.js',
name: 'tests'
}
Feature: Register user
Scenario: Success register
Given I located on register page
When I input my username "test_username" in field "username"
And I input password "123" in field "password"
And I click button "Sign Up"
Then I see text "Products list"
Scenario: Failed register already exist
Given I located on register page
When I input my username "test_username" in field "username"
And I input password "123" in field "password"
And I click button "Sign Up"
Then I see text "This user is already exists"
Scenario: Success register after already exist
Given I located on register page
When I input my username "test_username" in field "username"
And I input password "123" in field "password"
And I click button "Sign Up"
Then I see text "This user is already exists"
When I input my username "test_admin" in field "username"
And I input password "123" in field "password"
And I click button "Sign Up"
Then I see text "Products list"
Scenario: Failed register missing password
Given I located on register page
When I input my username "test_username1" in field "username"
And I input password "" in field "password"
And I click button "Sign Up"
Then I see text "Path `password` is required"
Scenario: Failed register missing username
Given I located on register page
When I input my username "" in field "username"
And I input password "123" in field "password"
And I click button "Sign Up"
Then I see text "Path `username` is required"
{
"compilerOptions": {
"allowJs": true
}
}
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
{
"dependencies": {
"codeceptjs": "^3.4.1",
"puppeteer": "^20.7.0"
},
"scripts": {
"start": "codeceptjs run --steps",
"gherkin:snippets": "codeceptjs gherkin:snippets"
}
}
#!/bin/bash
REAL_PATH=`dirname $0`
cd $REAL_PATH
CURRENT_DIR=`pwd`
cd $CURRENT_DIR/../api_client
npm run seed:test
cd $CURRENT_DIR/../tests
npm start
exit 0
const { I } = inject();
// Add in your custom step files
Given('I located on register page', () => {
I.amOnPage('/register');
});
When('I input my username {string} in field {string}', (text, field) => {
I.fillField({id: field}, text);
});
When('I input password {string} in field {string}', (text, field) => {
I.fillField({id: field}, text);
});
When('I click button {string}', (button) => {
I.click(button);
});
Then('I see text {string}', (text) => {
I.see(text);
});
/// <reference types='codeceptjs' />
type steps_file = typeof import('./steps_file.js');
declare namespace CodeceptJS {
interface SupportObject { I: I, current: any }
interface Methods extends Puppeteer {}
interface I extends ReturnType<steps_file> {}
namespace Translation {
interface Actions {}
}
}
// in this file you can append custom step methods to 'I' object
module.exports = function() {
return actor({
// Define custom steps here, use 'this' to access default methods of I.
// It is recommended to place a general 'login' function here.
});
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment