Skip to content

Commit

Permalink
chore: runnign e2e locally
Browse files Browse the repository at this point in the history
  • Loading branch information
Sciator committed Oct 6, 2020
1 parent ba8e0f9 commit 92c8adf
Show file tree
Hide file tree
Showing 19 changed files with 148 additions and 80 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ build
coverage
node_modules
vendor
temp
cypress/screenshots
cypress/videos
junit-results

# files
cypress.env.json
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
56 changes: 28 additions & 28 deletions cypress/e2e/dashboardsIndex.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/dashboardsView.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/loadDataSources.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
describe.skip('Load Data Sources', () => {
describe('Load Data Sources', () => {
beforeEach(() => {
cy.flush()

Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/login.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,4 @@ describe('The Login Page', () => {
cy.getByTestID('notification-error').should('exist')
})
})
})
})
2 changes: 1 addition & 1 deletion cypress/e2e/notificationEndpoints.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/notificationRules.test.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/onboarding.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/orgs.test.ts
Original file line number Diff line number Diff line change
@@ -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()
})
Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/scrapers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
48 changes: 24 additions & 24 deletions cypress/e2e/tasks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)'
)
})

Expand Down Expand Up @@ -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()
Expand All @@ -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'
)
})
})
Expand All @@ -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'
)
})
})
Expand Down
6 changes: 6 additions & 0 deletions cypress/fixtures/user.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"username": "u1",
"password": "password",
"org": "deforg",
"bucket": "defbuck"
}
33 changes: 20 additions & 13 deletions cypress/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,21 @@ import {NotificationEndpoint} from '../../src/types'
import 'cypress-file-upload'

export const signin = (): Cypress.Chainable<Cypress.Response> => {
/*\ 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')
Expand All @@ -24,6 +25,7 @@ export const signin = (): Cypress.Chainable<Cypress.Response> => {
.then(() => cy.get('#submit-login').click())
.then(() => cy.get('.theme-btn--success').click())
.then(() => cy.wrap(body))
\*/
})
}

Expand Down Expand Up @@ -436,19 +438,26 @@ 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<Cypress.Response> => {
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 = () => {
cy.request({
method: 'GET',
url: '/debug/flush',
})

cy.wait(500)
}

export const lines = (numLines = 3) => {
Expand All @@ -474,14 +483,12 @@ export const lines = (numLines = 3) => {
export const writeData = (
lines: string[]
): Cypress.Chainable<Cypress.Response> => {
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'),
})
})
}

Expand Down
14 changes: 8 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -30,22 +31,23 @@
"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",
"test:e2e:all": "yarn test:e2e:clean && yarn test:e2e; yarn test:e2e:report;",
"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"
},
Expand Down
17 changes: 17 additions & 0 deletions scripts/db:get.ts
Original file line number Diff line number Diff line change
@@ -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'})
12 changes: 12 additions & 0 deletions scripts/db:run.ts
Original file line number Diff line number Diff line change
@@ -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'}
)
Loading

0 comments on commit 92c8adf

Please sign in to comment.