From 92c8adf42579a558465c2b27b06ca8f4705ea4d7 Mon Sep 17 00:00:00 2001 From: TheRWe Date: Tue, 6 Oct 2020 13:16:41 +0200 Subject: [PATCH] chore: runnign e2e locally --- .gitignore | 4 ++ README.md | 6 +++ cypress/e2e/dashboardsIndex.test.ts | 56 +++++++++++------------ cypress/e2e/dashboardsView.test.ts | 2 +- cypress/e2e/loadDataSources.test.ts | 2 +- cypress/e2e/login.test.ts | 2 +- cypress/e2e/notificationEndpoints.test.ts | 2 +- cypress/e2e/notificationRules.test.ts | 2 +- cypress/e2e/onboarding.test.ts | 2 +- cypress/e2e/orgs.test.ts | 2 +- cypress/e2e/scrapers.test.ts | 2 +- cypress/e2e/tasks.test.ts | 48 +++++++++---------- cypress/fixtures/user.json | 6 +++ cypress/support/commands.ts | 33 +++++++------ package.json | 14 +++--- scripts/db:get.ts | 17 +++++++ scripts/db:run.ts | 12 +++++ scripts/tsconfig.json | 13 ++++++ tsconfig.test.json | 3 +- 19 files changed, 148 insertions(+), 80 deletions(-) create mode 100644 cypress/fixtures/user.json create mode 100644 scripts/db:get.ts create mode 100644 scripts/db:run.ts create mode 100644 scripts/tsconfig.json diff --git a/.gitignore b/.gitignore index dc79cd9877..d8b49cfaca 100644 --- a/.gitignore +++ b/.gitignore @@ -13,6 +13,10 @@ build coverage node_modules vendor +temp +cypress/screenshots +cypress/videos +junit-results # files cypress.env.json diff --git a/README.md b/README.md index 6ba288a11d..7a2c3473c9 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,12 @@ From the ui directory. Build the javascript with To run Cypress locally `$ yarn cy:dev` +### Run against influxdb master + 1. `yarn build` + 1. `yarn script db:get` clone database with git and build it + 1. `yarn script db:run` starts database (don't close terminal) + 1. `yarn cy` with ui or `yarn test:e2e` only run tests + ## Starting Dev Server Running `/ui` locally depends on `monitor-ci`. [See the monitor-ci Quickstart](https://github.com/influxdata/monitor-ci#quickstart-for-local-development) diff --git a/cypress/e2e/dashboardsIndex.test.ts b/cypress/e2e/dashboardsIndex.test.ts index 7dcf6e7bb0..6c87ee632c 100644 --- a/cypress/e2e/dashboardsIndex.test.ts +++ b/cypress/e2e/dashboardsIndex.test.ts @@ -118,34 +118,34 @@ describe('Dashboards', () => { cy.getByTestID('context-delete-dashboard').click() }) - const dashboardDescription = 'this dashboard contains secret information' - - // change description - cy.getByTestID('resource-list--editable-description') - .click('topLeft') - .within(() => { - cy.getByTestID('input-field') - .type(dashboardDescription) - .type('{enter}') - }) - cy.getByTestID('resource-list--editable-description').should( - 'contain', - dashboardDescription - ) - - // remove description - cy.getByTestID('resource-list--editable-description') - .click('topLeft') - .within(() => { - cy.getByTestID('input-field') - .clear() - .type('{enter}') - }) - cy.getByTestID('resource-list--editable-description').should( - 'not.contain', - dashboardDescription - ) - + const dashboardDescription = 'this dashboard contains secret information' + + // change description + cy.getByTestID('resource-list--editable-description') + .click('topLeft') + .within(() => { + cy.getByTestID('input-field') + .type(dashboardDescription) + .type('{enter}') + }) + cy.getByTestID('resource-list--editable-description').should( + 'contain', + dashboardDescription + ) + + // remove description + cy.getByTestID('resource-list--editable-description') + .click('topLeft') + .within(() => { + cy.getByTestID('input-field') + .clear() + .type('{enter}') + }) + cy.getByTestID('resource-list--editable-description').should( + 'not.contain', + dashboardDescription + ) + cy.getByTestID('dashboard-card') .first() .trigger('mouseover') diff --git a/cypress/e2e/dashboardsView.test.ts b/cypress/e2e/dashboardsView.test.ts index 82da4995b1..fe1c4ed988 100644 --- a/cypress/e2e/dashboardsView.test.ts +++ b/cypress/e2e/dashboardsView.test.ts @@ -187,7 +187,7 @@ describe('Dashboard', () => { cy.getByTestID('cell-context--delete').click() cy.getByTestID('cell-context--delete-confirm').click() cy.wait(200) - + // Clone View cell cy.getByTestID('cell-context--toggle').click() cy.getByTestID('cell-context--clone').click() diff --git a/cypress/e2e/loadDataSources.test.ts b/cypress/e2e/loadDataSources.test.ts index a3da1001ff..310ef10fc0 100644 --- a/cypress/e2e/loadDataSources.test.ts +++ b/cypress/e2e/loadDataSources.test.ts @@ -1,4 +1,4 @@ -describe.skip('Load Data Sources', () => { +describe('Load Data Sources', () => { beforeEach(() => { cy.flush() diff --git a/cypress/e2e/login.test.ts b/cypress/e2e/login.test.ts index f564a4948b..6778551f89 100644 --- a/cypress/e2e/login.test.ts +++ b/cypress/e2e/login.test.ts @@ -88,4 +88,4 @@ describe('The Login Page', () => { cy.getByTestID('notification-error').should('exist') }) }) -}) \ No newline at end of file +}) diff --git a/cypress/e2e/notificationEndpoints.test.ts b/cypress/e2e/notificationEndpoints.test.ts index cf30482123..75b078fb4e 100644 --- a/cypress/e2e/notificationEndpoints.test.ts +++ b/cypress/e2e/notificationEndpoints.test.ts @@ -5,7 +5,7 @@ import { } from '../../src/types' // skipping these tests until we have a local vault instance working -describe.skip('Notification Endpoints', () => { +describe('Notification Endpoints', () => { const endpoint: NotificationEndpoint = { orgID: '', name: 'Pre-Created Endpoint', diff --git a/cypress/e2e/notificationRules.test.ts b/cypress/e2e/notificationRules.test.ts index 67ac5b9a84..b5c6e4ba1b 100644 --- a/cypress/e2e/notificationRules.test.ts +++ b/cypress/e2e/notificationRules.test.ts @@ -1,7 +1,7 @@ import {SlackNotificationEndpoint, Organization} from '../../src/types' // skipping these tests until we have a local vault instance running -describe.skip('NotificationRules', () => { +describe('NotificationRules', () => { const name1 = 'Slack 1' const name2 = 'Slack 2' const name3 = 'Slack 3' diff --git a/cypress/e2e/onboarding.test.ts b/cypress/e2e/onboarding.test.ts index 0dc1156fda..d6c2e48dc3 100644 --- a/cypress/e2e/onboarding.test.ts +++ b/cypress/e2e/onboarding.test.ts @@ -11,7 +11,7 @@ describe('Onboarding Redirect', () => { }) // NOTE: important to test for OSS, not so much for cloud -describe.skip('Onboarding', () => { +describe('Onboarding', () => { beforeEach(() => { cy.flush() diff --git a/cypress/e2e/orgs.test.ts b/cypress/e2e/orgs.test.ts index 6dcd7d8116..3827a72945 100644 --- a/cypress/e2e/orgs.test.ts +++ b/cypress/e2e/orgs.test.ts @@ -1,7 +1,7 @@ const secondOrg = 'Second Org' // NOTE: this is dying for no reason in circleci -describe.skip('Orgs', () => { +describe('Orgs', () => { beforeEach(() => { cy.flush() }) diff --git a/cypress/e2e/scrapers.test.ts b/cypress/e2e/scrapers.test.ts index 6ef969a8ec..788808b8a3 100644 --- a/cypress/e2e/scrapers.test.ts +++ b/cypress/e2e/scrapers.test.ts @@ -5,7 +5,7 @@ const PAGE_LOAD_SLA = 10000 // NOTE // this isn't supported in cloud mode -describe.skip('Scrapers', () => { +describe('Scrapers', () => { beforeEach(() => { cy.flush() diff --git a/cypress/e2e/tasks.test.ts b/cypress/e2e/tasks.test.ts index 98f77a5b06..d952d4b6dd 100644 --- a/cypress/e2e/tasks.test.ts +++ b/cypress/e2e/tasks.test.ts @@ -173,13 +173,13 @@ http.post( .click() .type( 'option task = \n' + - '{\n' + - 'name: "Option Test", \n' + - 'every: 24h, \n' + - 'offset: 20m\n' + - '}\n' + - 'from(bucket: "defbuck")\n' + - '\t|> range(start: -2m)' + '{\n' + + 'name: "Option Test", \n' + + 'every: 24h, \n' + + 'offset: 20m\n' + + '}\n' + + 'from(bucket: "defbuck")\n' + + '\t|> range(start: -2m)' ) }) @@ -374,12 +374,12 @@ http.post( .should( 'have.value', 'option task = {\n' + - ' name: "🦄ask",\n' + - ' every: 24h,\n' + - ' offset: 20m\n' + - ' }\n' + - ' from(bucket: "defbuck")\n' + - ' |> range(start: -2m)' + ' name: "🦄ask",\n' + + ' every: 24h,\n' + + ' offset: 20m\n' + + ' }\n' + + ' from(bucket: "defbuck")\n' + + ' |> range(start: -2m)' ) .click() .focused() @@ -388,13 +388,13 @@ http.post( cy.get('textarea.inputarea').should( 'have.value', 'option task = {\n' + - ' name: "🦄ask",\n' + - ' every: 24h,\n' + - ' offset: 20m\n' + - ' }\n' + - ' from(bucket: "defbuck")\n' + - ' |> range(start: -2m) \n' + - ' //this is a test comment' + ' name: "🦄ask",\n' + + ' every: 24h,\n' + + ' offset: 20m\n' + + ' }\n' + + ' from(bucket: "defbuck")\n' + + ' |> range(start: -2m) \n' + + ' //this is a test comment' ) }) }) @@ -417,10 +417,10 @@ http.post( cy.get('textarea.inputarea').should( 'have.value', 'option task = {name: "🦄ask", every: 24h, offset: 20m}\n' + - '\n' + - 'from(bucket: "defbuck")\n' + - '\t|> range(start: -2m)\n' + - ' //this is a test comment' + '\n' + + 'from(bucket: "defbuck")\n' + + '\t|> range(start: -2m)\n' + + ' //this is a test comment' ) }) }) diff --git a/cypress/fixtures/user.json b/cypress/fixtures/user.json new file mode 100644 index 0000000000..d83ac5e6a1 --- /dev/null +++ b/cypress/fixtures/user.json @@ -0,0 +1,6 @@ +{ + "username": "u1", + "password": "password", + "org": "deforg", + "bucket": "defbuck" +} diff --git a/cypress/support/commands.ts b/cypress/support/commands.ts index c470639f6d..ad61f5d151 100644 --- a/cypress/support/commands.ts +++ b/cypress/support/commands.ts @@ -2,20 +2,21 @@ import {NotificationEndpoint} from '../../src/types' import 'cypress-file-upload' export const signin = (): Cypress.Chainable => { - /*\ OSS login + // OSS login + return cy.fixture('user').then(({username, password}) => { return cy.setupUser().then(body => { return cy .request({ method: 'POST', url: '/api/v2/signin', - auth: {user: Cypress.env('username'), pass: Cypress.env('password')}, + auth: {user: username, pass: password}, }) .then(() => { return cy.wrap(body) }) }) - \*/ + /*\ return cy.setupUser().then(body => { return cy .visit('/api/v2/signin') @@ -24,6 +25,7 @@ export const signin = (): Cypress.Chainable => { .then(() => cy.get('#submit-login').click()) .then(() => cy.get('.theme-btn--success').click()) .then(() => cy.wrap(body)) + \*/ }) } @@ -436,10 +438,19 @@ export const createToken = ( // TODO: have to go through setup because we cannot create a user w/ a password via the user API export const setupUser = (): Cypress.Chainable => { + return cy.fixture('user').then(({username, password, org, bucket}) => { + return cy.request({ + method: 'POST', + url: '/api/v2/setup', + body: {username, password, org, bucket}, + }) + }) + /*\ return cy.request({ method: 'GET', url: '/debug/provision', }) + \*/ } export const flush = () => { @@ -447,8 +458,6 @@ export const flush = () => { method: 'GET', url: '/debug/flush', }) - - cy.wait(500) } export const lines = (numLines = 3) => { @@ -474,14 +483,12 @@ export const lines = (numLines = 3) => { export const writeData = ( lines: string[] ): Cypress.Chainable => { - return cy.request({ - method: 'POST', - url: - '/api/v2/write?org=' + - Cypress.env('org') + - '&bucket=' + - Cypress.env('bucket'), - body: lines.join('\n'), + return cy.fixture('user').then(({org, bucket}) => { + cy.request({ + method: 'POST', + url: '/api/v2/write?org=' + org + '&bucket=' + bucket, + body: lines.join('\n'), + }) }) } diff --git a/package.json b/package.json index b5279346ec..de07c5ff1f 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,7 @@ "src": "./src" }, "scripts": { + "script": "cd ./scripts && ts-node-script", "start": "yarn install && yarn generate && cross-env TS_NODE_PROJECT=\"webpack.tsconfig.json\" && yarn run build:vendor && yarn run start:dev", "start:cloud": "yarn install && yarn generate && cross-env TS_NODE_PROJECT=\"webpack.tsconfig.json\" && yarn run build:vendor && yarn run start:dev-cloud", "start:dev": "webpack-dev-server --config ./webpack.dev.ts --progress false", @@ -30,7 +31,7 @@ "test:watch": "jest --watch --verbose false", "test:update": "jest --updateSnapshot", "test:debug": "node --inspect-brk $(npm bin)/jest --runInBand --watch --verbose false", - "test:e2e": "CYPRESS_baseUrl=http://localhost:9999 cypress run --browser chrome --reporter junit --reporter-options 'mochaFile=junit-results/test-output-[hash].xml'", + "test:e2e": "CYPRESS_baseUrl=http://localhost:8086 cypress run --browser chrome --reporter junit --reporter-options 'mochaFile=junit-results/test-output-[hash].xml'", "test:e2e:ci": "CYPRESS_baseUrl=https://localhost:443 cypress run --parallel --browser chrome --reporter junit --reporter-options 'mochaFile=junit-results/test-output-[hash].xml'", "test:e2e:report": "junit-viewer --results=junit-results --save-file=cypress/site/junit-report.html", "test:e2e:clean": "rm junit-results/*.xml", @@ -38,14 +39,15 @@ "test:circleci": "yarn run test:ci --maxWorkers=2", "test:ci": "JEST_JUNIT_OUTPUT_DIR=\"./coverage\" jest --ci --coverage", "lint": "yarn tsc && yarn prettier && yarn eslint", - "eslint": "eslint '{src,cypress}/**/*.{ts,tsx}'", + "lint:fix": "yarn prettier:fix && yarn eslint:fix", + "eslint": "eslint '{src,cypress,scripts}/**/*.{ts,tsx}'", "eslint:circleci": "eslint", - "eslint:fix": "eslint --fix '{src,cypress}/**/*.{ts,tsx}'", - "prettier": "prettier --config .prettierrc.json --check '{src,cypress}/**/*.{ts,tsx}'", - "prettier:fix": "prettier --config .prettierrc.json --write '{src,cypress}/**/*.{ts,tsx}'", + "eslint:fix": "eslint --fix '{src,cypress,scripts}/**/*.{ts,tsx}'", + "prettier": "prettier --config .prettierrc.json --check '{src,cypress,scripts}/**/*.{ts,tsx}'", + "prettier:fix": "prettier --config .prettierrc.json --write '{src,cypress,scripts}/**/*.{ts,tsx}'", "tsc": "tsc -p ./tsconfig.json --noEmit --pretty --skipLibCheck", "tsc:cypress": "tsc -p ./cypress/tsconfig.json --noEmit --pretty --skipLibCheck", - "cy": "CYPRESS_baseUrl=http://localhost:9999 cypress open", + "cy": "CYPRESS_baseUrl=http://localhost:8086 cypress open", "cy:dev": "CYPRESS_baseUrl=http://kubernetes.docker.internal:8080 cypress open", "generate": "oats https://raw.githubusercontent.com/influxdata/influxdb/master/http/swagger.yml > ./src/client/generatedRoutes.ts" }, diff --git a/scripts/db:get.ts b/scripts/db:get.ts new file mode 100644 index 0000000000..c369b982af --- /dev/null +++ b/scripts/db:get.ts @@ -0,0 +1,17 @@ +import {execSync} from 'child_process' +import * as fs from 'fs' + +const tempDir = '../temp/' +const influxGit = 'https://github.com/influxdb/influxdb.git' + +if (fs.existsSync(tempDir)) { + ;(fs.rmdirSync as any)(tempDir, {recursive: true}) +} + +fs.mkdirSync(tempDir) + +process.stdout.write(`Cloning influxdb from ${influxGit}`) +execSync(`git clone ${influxGit} --depth 1`, {cwd: tempDir, stdio: 'ignore'}) + +process.stdout.write(`building influxdb`) +execSync(`make`, {cwd: '../temp/influxdb', stdio: 'ignore'}) diff --git a/scripts/db:run.ts b/scripts/db:run.ts new file mode 100644 index 0000000000..f29b13b3d7 --- /dev/null +++ b/scripts/db:run.ts @@ -0,0 +1,12 @@ +import {exec, execSync} from 'child_process' +import * as path from 'path' + +const tempDir = '../temp/' +const influxdbDir = path.join(tempDir, 'influxdb') +const os = process.platform + +process.stdout.write(`Starting server...\n`) +execSync( + `./bin/${os}/influxd --assets-path=../../build --e2e-testing --store=memory --feature-flags=communityTemplates=true`, + {cwd: influxdbDir, stdio: 'inherit'} +) diff --git a/scripts/tsconfig.json b/scripts/tsconfig.json new file mode 100644 index 0000000000..31bf8eed75 --- /dev/null +++ b/scripts/tsconfig.json @@ -0,0 +1,13 @@ +{ + "compilerOptions": { + "target": "es6", + "module": "commonjs", + "resolveJsonModule": true, + "moduleResolution": "node", + "skipLibCheck": true, + "noEmit": true + }, + "include": [ + "./**/*.ts" + ] +} diff --git a/tsconfig.test.json b/tsconfig.test.json index 89febcb6f6..d44dfe6fc1 100644 --- a/tsconfig.test.json +++ b/tsconfig.test.json @@ -20,6 +20,7 @@ "mocks/**/*.ts", "mocks/**/*.tsx", "jestSetup.ts", - "global.d.ts" + "global.d.ts", + "scripts/**/*.ts" ] }