Skip to content

Commit

Permalink
add testing scripts (segmentio#428)
Browse files Browse the repository at this point in the history
  • Loading branch information
Xavier Agostini authored Dec 6, 2019
1 parent 9260e52 commit f2c8c6e
Show file tree
Hide file tree
Showing 14 changed files with 4,354 additions and 117 deletions.
1 change: 1 addition & 0 deletions .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
steps:
- label: ":hammer: Build Dependencies and Docs"
command:
- make test
- make build
- make zip-artifacts
env:
Expand Down
8 changes: 8 additions & 0 deletions .remarkrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"plugins": [
"remark-preset-lint-recommended",
["remark-lint-list-item-indent", "space"],
["remark-lint-list-item-bullet-indent", "space"],
["remark-lint-no-literal-urls", false]
]
}
16 changes: 16 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,22 @@ vendor/bundle:
@chmod -R 777 vendor/
@bundle install --path=vendor/bundle


.PHONY: lint
lint: node_modules
@echo "Checking yml files..."
@npx yamllint src/_data/**/*.yml
# @echo "Checking markdown files..."
# @npx remark ./src --use preset-lint-markdown-style-guide

.PHONY: test
test: lint

.PHONY: check-spelling
check-spelling:
@echo 'Check spelling in markdown files..."
@npx mdspell 'src/**/*.md' -r --en-us -h

.PHONY: docker-dev
docker-dev:
$(DOCKER_TTY) make dev
Expand Down
20 changes: 19 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -314,4 +314,22 @@ The current breadcrumb is currently determined based on the `page.path` and the
### Searching
Swiftype is set up as a script in `_layouts/default.html`

Test

## Testing

### Build Testing
Currently the only automatic testing we perform is linting on the configuration yaml files to ensure proper the project will build.

TODO: define rules for markdown linting and clean up linting errors
`npx remark ./src --use preset-lint-markdown-style-guide`

### Manual Testing
There is as also some manual testing scripts that can be run to validate the build.

1. `tests/redirects/redirects_bash`: used for validating a list of paths that we have nginx redirects for

2. `tests/externalLinks/linkTester_bash`: used to validate that external links referenced in docs point to a validate endpoint

3. `tests/imageSizes/getImageSizes.js`: used to get the 10 largest images in the repo.

4. `npx mdspell 'src/**/*.md' -r --en-us`: used to validate spelling in docs, needs to be configured to add Segment terms.
15 changes: 14 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
"author": "Jeff Knight <[email protected]>",
"license": "UNLICENSED",
"private": true,
"remarkConfig": {
"plugins": [
"remark-preset-lint-recommended"
]
},
"devDependencies": {
"@babel/cli": "7.6.0",
"@babel/core": "7.6.0",
Expand All @@ -18,9 +23,17 @@
"front-matter": "3.0.2",
"glob": "7.1.4",
"js-yaml": "3.13.1",
"markdown-link-extractor": "^1.2.2",
"markdown-spellcheck": "^1.3.1",
"remark": "^11.0.2",
"remark-cli": "^7.0.1",
"remark-lint": "^6.0.5",
"remark-preset-lint-markdown-style-guide": "^2.1.3",
"remark-preset-lint-recommended": "^3.0.3",
"superagent": "5.1.0",
"webpack": "4.40.2",
"webpack-cli": "3.3.9"
"webpack-cli": "3.3.9",
"yaml-lint": "^1.2.4"
},
"dependencies": {
"@babel/runtime": "7.7.2",
Expand Down
2 changes: 1 addition & 1 deletion src/_data/sidenav/api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ sections:
title: Reference
menu_icon: new-tab
- path: /config-api/tutorial-javascript-google-analytics
title: Creating a Javascript web source and Google Analytics destination
title: Creating a Javascript web source and Google Analytics destination
4 changes: 2 additions & 2 deletions src/guides/how-to-guides/migrate-from-other-tools.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ title: How do I migrate code from other analytics tools?

Switching from your current client-side javascript event tracking to Segment is easy. Below you can find migration guides for the following tools:

- Google Analytics
- Mixpanel
- Google Analytics
- Mixpanel

If you'd like us to add more tools or mobile/server-side examples to this guide [let us know](https://segment.com/help/contact/)!

Expand Down
14 changes: 14 additions & 0 deletions tests/externalLinks/getExternalLinks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const fs = require('fs')
const glob = require('glob')
const markdownLinkExtractor = require('markdown-link-extractor')

// Find all external links in our docs
const files = glob.sync('src/**/*.md')
const externalLinkPattern = /^https?\:\/\/(?!segment)/
files.reduce((accum, file) => {
let markdown = fs.readFileSync(file, 'utf8').toString()
const links = markdownLinkExtractor(markdown)
links.forEach(function (link) {
if (externalLinkPattern.test(link)) console.log(link)
})
})
20 changes: 20 additions & 0 deletions tests/externalLinks/linkTester_bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash

# used for validating external links from docs

list=$(node tests/externalLinks/getExternalLinks.js)

check_link () {
output=`curl -sS -H -v -o /dev/null -IL -w "%{http_code}" $1`
if [ "$output" != "200" ]; then
echo $1 $output
fi
}

echo "Testing redirects..."
while read -r p; do
check_link $p &
done <<< "$list"

wait
exit 1
28 changes: 28 additions & 0 deletions tests/imageSizes/getImageSizes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const fs = require('fs')
const glob = require('glob')

// Find all external links in our docs
const images = glob.sync('src/**/images/*')
var imageSizeArr = []
let i = 0
images.reduce((accum, image) => {
let stats = fs.statSync(image)
let fileSizeInBytes = stats["size"]
// console.log(image, fileSizeInBytes)
imageSizeArr.push({image, fileSizeInBytes})
i++
})


imageSizeArr = imageSizeArr.sort(function (a, b) {
return a.fileSizeInBytes - b.fileSizeInBytes;
});

console.log('Total Number of Images:', i)
console.log('Top 10 Largest Images (MB)')
const top10Images = imageSizeArr.slice(imageSizeArr.length-10,imageSizeArr.length)
top10Images.reduce((accum, image) => {
console.log(`${image.image}: ${image.fileSizeInBytes/1000000} MB`)
})


14 changes: 11 additions & 3 deletions tests/redirects/redirects_bash
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,19 @@
## add --cookie $oauth2_proxy_segment for staging
# grab okta oauth token from browser cookie for that
# output=`curl --cookie $oauth2_proxy_segment -sS -H -v -o /dev/null -IL -w "%{http_code}" ${url}`
echo "Testing redirects..."

while read p; do
url="https://segment.build${p}"
check_link () {
url="https://segment.com$1"
output=`curl -sS -H -v -o /dev/null -IL -w "%{http_code}" ${url}`
if [ "$output" != "200" ]; then
echo $p $output
echo $1 $output
fi
}

while read p; do
check_link $p &
done < tests/redirects/testPaths.txt

wait
exit 1
23 changes: 1 addition & 22 deletions tests/redirects/testPaths.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,14 @@
/docs/connections/destinations/catalog/iron.io/
/docs/connections/destinations/catalog/keen-io
/docs/connections/destinations/catalog/keen-io/
/docs/connections/destinations/catalog/optimizely-full-stack/index.md
/docs/connections/destinations/catalog/optimizely/
/docs/connections/destinations/catalog/optimizelyx/
/docs/connections/destinations/catalog/optimizelyx/index.md
/docs/connections/destinations/catalog/promoter.io/
/docs/connections/destinations/catalog/survicate/[email protected]
/docs/connections/destinations/catalog/trak.io/
/docs/connections/destinations/catalog/tray.io/
/docs/connections/destinations/catalog/webengage/[email protected]
/docs/connections/sources/catalog/cloud-apps/aircall/[email protected]
/docs/connections/sources/catalog/cloud-apps/appboy/
/docs/connections/sources/catalog/cloud-apps/delighted/[email protected]
/docs/connections/sources/catalog/libraries/mobile/ios/install-the-sdk
/docs/connections/sources/catalog/libraries/server
/docs/connections/sources/catalog/libraries/website/analytics.js
/docs/connections/sources/catalog/libraries/website/cross-domain
/docs/connections/sources/catalog/libraries/website/pixel/
/docs/connections/sources/catalog/libraries/website/plugins/
/docs/connections/sources/catalog/libraries/website/tracking-api
/docs/connections/sources/catalog/mobile/android/quickstart/
/docs/connections/sources/catalog/mobile/ios/quickstart/
/docs/connections/sources/catalog/server/go/quickstart/
Expand All @@ -34,9 +23,7 @@
/docs/connections/sources/catalog/server/python/quickstart/
/docs/connections/sources/catalog/server/ruby/quickstart/
/docs/connections/sources/catalog/server/rust/quickstart/
/docs/connections/sources/custom/
/docs/connections/sources/iterable/
/docs/connections/spec/reset/
/docs/connections/warehouses/add-users/
/docs/connections/warehouses/catalog/azuresqldb/
/docs/connections/warehouses/warehouse-faqs/
Expand All @@ -61,7 +48,6 @@
/docs/destinations/radiumone-connect
/docs/destinations/spinnakr
/docs/destinations/stitch-data
/docs/destinations/survicate/[email protected]
/docs/destinations/tapstream
/docs/destinations/trak.io/
/docs/destinations/xplenty
Expand Down Expand Up @@ -95,24 +81,17 @@
/docs/guides/warehouses/source-slug/
/docs/guides/warehouses/whitelist-ip-addresses
/docs/guides/warehouses/whitelist-ip-addresses/
/docs/integrations/autosend/
/docs/integrations/chartio/
/docs/integrations/customer.io/
/docs/integrations/freshdesk/
/docs/integrations/keen-io/
/docs/integrations/knowtify/
/docs/integrations/looker/
/docs/integrations/marketo/
/docs/integrations/mode/
/docs/integrations/mojn/
/docs/integrations/periscope.io/
/docs/integrations/tableau/
/docs/legal/[email protected]
/docs/personas/trait-and-audience-building/
/docs/asdfasdfasdf/asdf
/docs/protcols/ecommerce-tracking-plan/
/docs/segment.com
/docs/sources/cloud-apps/aircall/[email protected]
/docs/sources/cloud-apps/delighted/[email protected]
/docs/sources/website/guides/
/docs/sources/website/guides/magento
/docs/sources/website/guides/magento/
Expand Down
Loading

0 comments on commit f2c8c6e

Please sign in to comment.