From b81ff340b1ab42254de1612c3264867205b0112f Mon Sep 17 00:00:00 2001 From: syuilo Date: Thu, 12 Aug 2021 19:05:07 +0900 Subject: [PATCH] Introduce e2e test --- cypress.json | 3 + cypress/fixtures/example.json | 5 + cypress/integration/basic.js | 69 +++ cypress/plugins/index.js | 22 + cypress/support/commands.js | 25 + cypress/support/index.js | 20 + package.json | 14 +- src/argv.ts | 2 +- src/client/components/post-form.vue | 4 +- src/client/components/signin.vue | 4 +- src/client/components/signup.vue | 8 +- src/client/instance.ts | 2 + src/client/pages/welcome.entrance.a.vue | 4 +- src/client/pages/welcome.setup.vue | 8 +- src/client/ui/default.sidebar.vue | 2 +- src/db/postgre.ts | 10 + src/server/api/endpoints/reset-db.ts | 21 + yarn.lock | 614 +++++++++++++++++++++++- 18 files changed, 805 insertions(+), 32 deletions(-) create mode 100644 cypress.json create mode 100644 cypress/fixtures/example.json create mode 100644 cypress/integration/basic.js create mode 100644 cypress/plugins/index.js create mode 100644 cypress/support/commands.js create mode 100644 cypress/support/index.js create mode 100644 src/server/api/endpoints/reset-db.ts diff --git a/cypress.json b/cypress.json new file mode 100644 index 0000000000..f2c02689e4 --- /dev/null +++ b/cypress.json @@ -0,0 +1,3 @@ +{ + "baseUrl": "http://localhost" +} diff --git a/cypress/fixtures/example.json b/cypress/fixtures/example.json new file mode 100644 index 0000000000..02e4254378 --- /dev/null +++ b/cypress/fixtures/example.json @@ -0,0 +1,5 @@ +{ + "name": "Using fixtures to represent data", + "email": "hello@cypress.io", + "body": "Fixtures are a great way to mock data for responses to routes" +} diff --git a/cypress/integration/basic.js b/cypress/integration/basic.js new file mode 100644 index 0000000000..69d59bc2c6 --- /dev/null +++ b/cypress/integration/basic.js @@ -0,0 +1,69 @@ +describe('Basic', () => { + before(() => { + cy.request('POST', '/api/reset-db'); + }); + + beforeEach(() => { + cy.reload(true); + }); + + it('successfully loads', () => { + cy.visit('/'); + }); + + it('setup instance', () => { + cy.visit('/'); + + cy.get('[data-cy-admin-username] input').type('admin'); + + cy.get('[data-cy-admin-password] input').type('admin1234'); + + cy.get('[data-cy-admin-ok]').click(); + }); + + it('signup', () => { + cy.visit('/'); + + cy.get('[data-cy-signup]').click(); + + cy.get('[data-cy-signup-username] input').type('alice'); + + cy.get('[data-cy-signup-password] input').type('alice1234'); + + cy.get('[data-cy-signup-password-retype] input').type('alice1234'); + + cy.get('[data-cy-signup-submit]').click(); + }); + + it('signin', () => { + cy.visit('/'); + + cy.get('[data-cy-signin]').click(); + + cy.get('[data-cy-signin-username] input').type('alice'); + + // Enterキーでサインインできるかの確認も兼ねる + cy.get('[data-cy-signin-password] input').type('alice1234{enter}'); + }); + + it('note', () => { + cy.visit('/'); + + //#region TODO: この辺はUI操作ではなくAPI操作でログインする + cy.get('[data-cy-signin]').click(); + + cy.get('[data-cy-signin-username] input').type('alice'); + + // Enterキーでサインインできるかの確認も兼ねる + cy.get('[data-cy-signin-password] input').type('alice1234{enter}'); + //#endregion + + cy.get('[data-cy-open-post-form]').click(); + + cy.get('[data-cy-post-form-text]').type('Hello, Misskey!'); + + cy.get('[data-cy-open-post-form-submit]').click(); + + // TODO: 投稿した文字列が画面内にあるか(=タイムラインに流れてきたか)のテスト + }); +}); diff --git a/cypress/plugins/index.js b/cypress/plugins/index.js new file mode 100644 index 0000000000..59b2bab6e4 --- /dev/null +++ b/cypress/plugins/index.js @@ -0,0 +1,22 @@ +/// +// *********************************************************** +// This example plugins/index.js can be used to load plugins +// +// You can change the location of this file or turn off loading +// the plugins file with the 'pluginsFile' configuration option. +// +// You can read more here: +// https://on.cypress.io/plugins-guide +// *********************************************************** + +// This function is called when a project is opened or re-opened (e.g. due to +// the project's config changing) + +/** + * @type {Cypress.PluginConfig} + */ +// eslint-disable-next-line no-unused-vars +module.exports = (on, config) => { + // `on` is used to hook into various events Cypress emits + // `config` is the resolved Cypress config +} diff --git a/cypress/support/commands.js b/cypress/support/commands.js new file mode 100644 index 0000000000..119ab03f7c --- /dev/null +++ b/cypress/support/commands.js @@ -0,0 +1,25 @@ +// *********************************************** +// This example commands.js shows you how to +// create various custom commands and overwrite +// existing commands. +// +// For more comprehensive examples of custom +// commands please read more here: +// https://on.cypress.io/custom-commands +// *********************************************** +// +// +// -- This is a parent command -- +// Cypress.Commands.add('login', (email, password) => { ... }) +// +// +// -- This is a child command -- +// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... }) +// +// +// -- This is a dual command -- +// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... }) +// +// +// -- This will overwrite an existing command -- +// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... }) diff --git a/cypress/support/index.js b/cypress/support/index.js new file mode 100644 index 0000000000..d68db96df2 --- /dev/null +++ b/cypress/support/index.js @@ -0,0 +1,20 @@ +// *********************************************************** +// This example support/index.js is processed and +// loaded automatically before your test files. +// +// This is a great place to put global configuration and +// behavior that modifies Cypress. +// +// You can change the location of this file or turn off +// automatically serving support files with the +// 'supportFile' configuration option. +// +// You can read more here: +// https://on.cypress.io/configuration +// *********************************************************** + +// Import commands.js using ES2015 syntax: +import './commands' + +// Alternatively you can use CommonJS syntax: +// require('./commands') diff --git a/package.json b/package.json index 1db1044777..79a312725a 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ "private": true, "scripts": { "start": "node ./index.js", + "start:test": "cross-env NODE_ENV=test node ./index.js", "init": "npm run migrate", "ormconfig": "node ./built/ormconfig.js", "migrate": "ts-node ./node_modules/typeorm/cli.js migration:run", @@ -26,6 +27,9 @@ "clean": "gulp clean", "cleanall": "gulp cleanall", "lint": "tslint 'src/**/*.ts'", + "cy:open": "cypress open", + "cy:run": "cypress run", + "e2e": "start-server-and-test start:test http://localhost cy:run", "test": "cross-env TS_NODE_FILES=true TS_NODE_TRANSPILE_ONLY=true TS_NODE_PROJECT=\"./test/tsconfig.json\" mocha", "format": "gulp format" }, @@ -57,6 +61,9 @@ "@types/jsonld": "1.5.6", "@types/katex": "0.11.1", "@types/koa": "2.13.4", + "@types/koa__cors": "3.0.3", + "@types/koa__multer": "2.0.3", + "@types/koa__router": "8.0.7", "@types/koa-bodyparser": "4.3.3", "@types/koa-cors": "0.0.2", "@types/koa-favicon": "2.0.21", @@ -64,9 +71,6 @@ "@types/koa-mount": "4.0.0", "@types/koa-send": "4.1.3", "@types/koa-views": "7.0.0", - "@types/koa__cors": "3.0.3", - "@types/koa__multer": "2.0.3", - "@types/koa__router": "8.0.7", "@types/markdown-it": "12.0.3", "@types/matter-js": "0.17.5", "@types/mocha": "8.2.3", @@ -259,6 +263,8 @@ "@types/chai": "4.2.16", "@types/fluent-ffmpeg": "2.1.17", "chai": "4.3.4", - "cross-env": "7.0.3" + "cross-env": "7.0.3", + "cypress": "8.2.0", + "start-server-and-test": "1.13.1" } } diff --git a/src/argv.ts b/src/argv.ts index ae6396129c..8e00bcf47d 100644 --- a/src/argv.ts +++ b/src/argv.ts @@ -18,7 +18,7 @@ program if (process.env.MK_ONLY_QUEUE) program.onlyQueue = true; if (process.env.NODE_ENV === 'test') program.disableClustering = true; -if (process.env.NODE_ENV === 'test') program.quiet = true; +//if (process.env.NODE_ENV === 'test') program.quiet = true; if (process.env.NODE_ENV === 'test') program.noDaemons = true; export { program }; diff --git a/src/client/components/post-form.vue b/src/client/components/post-form.vue index f2c625a556..221dc74313 100644 --- a/src/client/components/post-form.vue +++ b/src/client/components/post-form.vue @@ -17,7 +17,7 @@ - +
@@ -36,7 +36,7 @@
{{ $ts.notSpecifiedMentionWarning }} - -