Skip to content

Commit

Permalink
feat: add web smoke tests
Browse files Browse the repository at this point in the history
Restructure and add Sourcegraph instance smoke tests
  • Loading branch information
umpox committed Mar 21, 2022
2 parents 1068371 + c31c639 commit 0c3524b
Show file tree
Hide file tree
Showing 28 changed files with 7,340 additions and 981 deletions.
15 changes: 15 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module.exports = {
extends: ['@sourcegraph/eslint-config'],
env: {
node: true,
es6: true,
},
parserOptions: {
ecmaVersion: 2018,
sourceType: 'module',
EXPERIMENTAL_useSourceOfProjectReferenceRedirect: true,
project: ['./packages/**/tsconfig.json'],
tsconfigRootDir: __dirname,
warnOnUnsupportedTypeScriptVersion: false,
},
}
39 changes: 39 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: build

on: [push, pull_request]

env:
FORCE_COLOR: 3

defaults:
run:
working-directory: packages/web-functionality

jobs:
build-web-functionality:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

# set up correct version of node
- id: nvmrc
run: echo ::set-output name=NODE_VERSION::$(cat ../../.nvmrc)
- uses: actions/setup-node@v2
with: { node-version: '${{ steps.nvmrc.outputs.NODE_VERSION }}' }

- run: yarn

# checks
- run: yarn run prettier-check
- run: yarn run eslint

# build
- run: yarn run build

# publish
- name: release
if: github.event_name == 'push'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
run: yarn run semantic-release
10 changes: 5 additions & 5 deletions .github/workflows/lighthouse.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ on:
workflow_dispatch:
schedule:
# Every 4 hours
- cron: "0 */4 * * *"
- cron: '0 */4 * * *'

jobs:
update:
Expand All @@ -15,7 +15,7 @@ jobs:
- id: nvmrc
run: echo ::set-output name=NODE_VERSION::$(cat .nvmrc)
- uses: actions/setup-node@v2
with: { node-version: "${{ steps.nvmrc.outputs.NODE_VERSION }}" }
with: { node-version: '${{ steps.nvmrc.outputs.NODE_VERSION }}' }

- name: Install dependencies
run: yarn --ignore-engines --ignore-scripts
Expand All @@ -24,9 +24,9 @@ jobs:
working-directory: ./packages/web-performance
run: |
./report.sh ":house: *Homepage*" "https://sourcegraph.com/search" ./reports/homepage.json
./report.sh ":mag_right: *Search results*" "https://sourcegraph.com/search?q=repo:sourcegraph/lighthouse-ci-test-repository+file:index.js" ./reports/search.json
./report.sh ":repository: *Repository page*" "https://sourcegraph.com/github.com/sourcegraph/lighthouse-ci-test-repository" ./reports/repository.json
./report.sh ":code: *File blob*" "https://sourcegraph.com/github.com/sourcegraph/lighthouse-ci-test-repository/-/blob/index.js" ./reports/file_blob.json
./report.sh ":mag_right: *Search results*" "https://sourcegraph.com/search?q=repo:sourcegraph/smoke-tests-test-repository+file:index.js" ./reports/search.json
./report.sh ":repository: *Repository page*" "https://sourcegraph.com/github.com/sourcegraph/smoke-tests-test-repository" ./reports/repository.json
./report.sh ":code: *File blob*" "https://sourcegraph.com/github.com/sourcegraph/smoke-tests-test-repository/-/blob/index.js" ./reports/file_blob.json
- name: Commit results
run: |
Expand Down
117 changes: 18 additions & 99 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,104 +1,23 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
# Vim
*.swp

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
# JetBrains/IntelliJ
.idea

# Runtime data
pids
*.pid
*.seed
*.pid.lock
# Emacs
*~
\#*\#
/.emacs.desktop
/.emacs.desktop.lock
.\#*
.dir-locals.el

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Mac OS X
.DS_Store

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# TypeScript v1 declaration files
typings/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env
.env.test

# parcel-bundler cache (https://parceljs.org/)
.cache

# Next.js build output
.next

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and *not* Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port
node_modules
npm-debug.log
yarn-error.log
.eslintcache
*.tsbuildinfo
7 changes: 7 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
**/fixtures/**/*
**/dist
**/coverage
**/.vscode
**/.vs
**/packages/web-performance/reports
**/packages/web-performance/.lighthouseci
11 changes: 11 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"editor.formatOnSave": true,
"typescript.format.semicolons": "remove",
"eslint.validate": ["javascript", "typescript"],
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true,
},
"eslint.packageManager": "yarn",
"eslint.codeActionsOnSave.mode": "problems",
"eslint.options": { "cache": true },
}
16 changes: 14 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
## Smoke tests at Sourcegraph
## Sourcegraph Smoke tests

TODO
This repository contains a series of smoke tests that can be ran against Sourcegraph instances.

### Web functionality

Series of checks that assess if a Sourcegraph instance is functioning properly.

See the [README](./packages/web-functionality/README.md) for more information.

### Web performance

Series of Lighthouse audits that measure web performance on Sourcegraph.com

See the [README](./packages/web-performance/README.md) for more information.
35 changes: 25 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,34 @@
{
"name": "smoke-tests",
"name": "@sourcegraph/smoke-tests",
"version": "1.0.0",
"description": "Smoke tests against Sourcegraph applications",
"private": true,
"workspaces": ["packages/*"],
"dependencies": {},
"devDependencies": {},
"workspaces": [
"packages/*"
],
"dependencies": {
"@commitlint/cli": "^14.1.0",
"@commitlint/config-conventional": "^14.1.0",
"@sourcegraph/eslint-config": "^0.27.0",
"@sourcegraph/prettierrc": "^3.0.3",
"eslint": "^7.32.0",
"husky": "^4.3.5",
"prettier": "^2.6.0",
"semantic-release": "^17.1.2"
},
"commitlint": {
"extends": [
"@commitlint/config-conventional"
]
},
"husky": {
"hooks": {
"commit-msg": "commitlint -e $HUSKY_GIT_PARAMS"
}
},
"repository": {
"type": "git",
"url": "git+https://github.com/sourcegraph/smoke-tests.git"
},
"author": "",
"license": "Apache-2.0",
"bugs": {
"url": "https://github.com/sourcegraph/smoke-tests/issues"
},
"homepage": "https://github.com/sourcegraph/smoke-tests#readme"
"license": "Apache-2.0"
}
3 changes: 3 additions & 0 deletions packages/web-functionality/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
lib
jest.config.js
jest-puppeteer.config.js
1 change: 1 addition & 0 deletions packages/web-functionality/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lib
23 changes: 20 additions & 3 deletions packages/web-functionality/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
# smoke-tests [DRAFT]
## Smoke tests: Web functionality

A proposal for basic smoke tests, which could be plugged in [Cloud deploy pipeline](https://buildkite.com/sourcegraph/deploy-sourcegraph-cloud) to ensure basic happy paths are working (or used on schedule).
These smoke tests run some basic checks against a deployed Sourcegraph instance.

[CodeceptJS](https://codecept.io/) with [Puppeter helper](https://codecept.io/helpers/Puppeteer/) was used, just b/c it is quite easy to replace helper to support more browsers at any point.
### How to run

`SOURCEGRAPH_URL="https://sourcegraph.com" npx @sourcegraph/web-smoke-tests@latest start`

### Environment reference

| Variable | Meaning |
| ------------------------ | :--------------------------------------------------------------------------------------------------: |
| `SOURCEGRAPH_URL` | The URL of the deployed instance to run checks against |
| `JEST_JUNIT_OUTPUT_NAME` | The name of a generated JUnit report summary for failure analysis. Default is "junit.xml". |
| `JEST_JUNIT_OUTPUT_DIR` | The directory in which the generated JUnit report should be stored. Default is the current directory |

## Releases

Releases are done automatically in CI when commits are merged into master by analyzing [Conventional Commit Messages](https://conventionalcommits.org/).
After running `yarn`, commit messages will be linted automatically when committing though a git hook.
The git hook can be circumvented for fixup commits with [git's `fixup!` autosquash feature](https://fle.github.io/git-tip-keep-your-branch-clean-with-fixup-and-autosquash.html), or by passing `--no-verify` to `git commit`.
You may have to rebase a branch before merging to ensure it has a proper commit history, or squash merge with a manually edited commit message that conforms to the convention.
35 changes: 0 additions & 35 deletions packages/web-functionality/codecept.conf.js

This file was deleted.

6 changes: 6 additions & 0 deletions packages/web-functionality/jest-puppeteer.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
launch: {
headless: process.env.HEADLESS !== 'false',
product: 'chrome',
},
}
11 changes: 11 additions & 0 deletions packages/web-functionality/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module.exports = {
preset: 'jest-puppeteer',
haste: {
providesModuleNodeModules: ['.*'],
},
testMatch: ['<rootDir>/lib/**/*.test.js'],
testPathIgnorePatterns: ['<rootDir>/node_modules/'],
transformIgnorePatterns: ['<rootDir>/node_modules/'],
modulePathIgnorePatterns: ['<rootDir>/node_modules/'],
testResultsProcessor: 'jest-junit',
}
Loading

0 comments on commit 0c3524b

Please sign in to comment.