Skip to content

Commit f2c8c6e

Browse files
author
Xavier Agostini
authored
add testing scripts (#428)
1 parent 9260e52 commit f2c8c6e

File tree

14 files changed

+4354
-117
lines changed

14 files changed

+4354
-117
lines changed

.buildkite/pipeline.yml

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
steps:
22
- label: ":hammer: Build Dependencies and Docs"
33
command:
4+
- make test
45
- make build
56
- make zip-artifacts
67
env:

.remarkrc

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"plugins": [
3+
"remark-preset-lint-recommended",
4+
["remark-lint-list-item-indent", "space"],
5+
["remark-lint-list-item-bullet-indent", "space"],
6+
["remark-lint-no-literal-urls", false]
7+
]
8+
}

Makefile

+16
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,22 @@ vendor/bundle:
9393
@chmod -R 777 vendor/
9494
@bundle install --path=vendor/bundle
9595

96+
97+
.PHONY: lint
98+
lint: node_modules
99+
@echo "Checking yml files..."
100+
@npx yamllint src/_data/**/*.yml
101+
# @echo "Checking markdown files..."
102+
# @npx remark ./src --use preset-lint-markdown-style-guide
103+
104+
.PHONY: test
105+
test: lint
106+
107+
.PHONY: check-spelling
108+
check-spelling:
109+
@echo 'Check spelling in markdown files..."
110+
@npx mdspell 'src/**/*.md' -r --en-us -h
111+
96112
.PHONY: docker-dev
97113
docker-dev:
98114
$(DOCKER_TTY) make dev

README.md

+19-1
Original file line numberDiff line numberDiff line change
@@ -314,4 +314,22 @@ The current breadcrumb is currently determined based on the `page.path` and the
314314
### Searching
315315
Swiftype is set up as a script in `_layouts/default.html`
316316

317-
Test
317+
318+
## Testing
319+
320+
### Build Testing
321+
Currently the only automatic testing we perform is linting on the configuration yaml files to ensure proper the project will build.
322+
323+
TODO: define rules for markdown linting and clean up linting errors
324+
`npx remark ./src --use preset-lint-markdown-style-guide`
325+
326+
### Manual Testing
327+
There is as also some manual testing scripts that can be run to validate the build.
328+
329+
1. `tests/redirects/redirects_bash`: used for validating a list of paths that we have nginx redirects for
330+
331+
2. `tests/externalLinks/linkTester_bash`: used to validate that external links referenced in docs point to a validate endpoint
332+
333+
3. `tests/imageSizes/getImageSizes.js`: used to get the 10 largest images in the repo.
334+
335+
4. `npx mdspell 'src/**/*.md' -r --en-us`: used to validate spelling in docs, needs to be configured to add Segment terms.

package.json

+14-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55
"author": "Jeff Knight <[email protected]>",
66
"license": "UNLICENSED",
77
"private": true,
8+
"remarkConfig": {
9+
"plugins": [
10+
"remark-preset-lint-recommended"
11+
]
12+
},
813
"devDependencies": {
914
"@babel/cli": "7.6.0",
1015
"@babel/core": "7.6.0",
@@ -18,9 +23,17 @@
1823
"front-matter": "3.0.2",
1924
"glob": "7.1.4",
2025
"js-yaml": "3.13.1",
26+
"markdown-link-extractor": "^1.2.2",
27+
"markdown-spellcheck": "^1.3.1",
28+
"remark": "^11.0.2",
29+
"remark-cli": "^7.0.1",
30+
"remark-lint": "^6.0.5",
31+
"remark-preset-lint-markdown-style-guide": "^2.1.3",
32+
"remark-preset-lint-recommended": "^3.0.3",
2133
"superagent": "5.1.0",
2234
"webpack": "4.40.2",
23-
"webpack-cli": "3.3.9"
35+
"webpack-cli": "3.3.9",
36+
"yaml-lint": "^1.2.4"
2437
},
2538
"dependencies": {
2639
"@babel/runtime": "7.7.2",

src/_data/sidenav/api.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ sections:
1414
title: Reference
1515
menu_icon: new-tab
1616
- path: /config-api/tutorial-javascript-google-analytics
17-
title: Creating a Javascript web source and Google Analytics destination
17+
title: Creating a Javascript web source and Google Analytics destination

src/guides/how-to-guides/migrate-from-other-tools.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ title: How do I migrate code from other analytics tools?
44

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

7-
- Google Analytics
8-
- Mixpanel
7+
- Google Analytics
8+
- Mixpanel
99

1010
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/)!
1111

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
const fs = require('fs')
2+
const glob = require('glob')
3+
const markdownLinkExtractor = require('markdown-link-extractor')
4+
5+
// Find all external links in our docs
6+
const files = glob.sync('src/**/*.md')
7+
const externalLinkPattern = /^https?\:\/\/(?!segment)/
8+
files.reduce((accum, file) => {
9+
let markdown = fs.readFileSync(file, 'utf8').toString()
10+
const links = markdownLinkExtractor(markdown)
11+
links.forEach(function (link) {
12+
if (externalLinkPattern.test(link)) console.log(link)
13+
})
14+
})

tests/externalLinks/linkTester_bash

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/bash
2+
3+
# used for validating external links from docs
4+
5+
list=$(node tests/externalLinks/getExternalLinks.js)
6+
7+
check_link () {
8+
output=`curl -sS -H -v -o /dev/null -IL -w "%{http_code}" $1`
9+
if [ "$output" != "200" ]; then
10+
echo $1 $output
11+
fi
12+
}
13+
14+
echo "Testing redirects..."
15+
while read -r p; do
16+
check_link $p &
17+
done <<< "$list"
18+
19+
wait
20+
exit 1

tests/imageSizes/getImageSizes.js

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
const fs = require('fs')
2+
const glob = require('glob')
3+
4+
// Find all external links in our docs
5+
const images = glob.sync('src/**/images/*')
6+
var imageSizeArr = []
7+
let i = 0
8+
images.reduce((accum, image) => {
9+
let stats = fs.statSync(image)
10+
let fileSizeInBytes = stats["size"]
11+
// console.log(image, fileSizeInBytes)
12+
imageSizeArr.push({image, fileSizeInBytes})
13+
i++
14+
})
15+
16+
17+
imageSizeArr = imageSizeArr.sort(function (a, b) {
18+
return a.fileSizeInBytes - b.fileSizeInBytes;
19+
});
20+
21+
console.log('Total Number of Images:', i)
22+
console.log('Top 10 Largest Images (MB)')
23+
const top10Images = imageSizeArr.slice(imageSizeArr.length-10,imageSizeArr.length)
24+
top10Images.reduce((accum, image) => {
25+
console.log(`${image.image}: ${image.fileSizeInBytes/1000000} MB`)
26+
})
27+
28+

tests/redirects/redirects_bash

+11-3
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,19 @@
33
## add --cookie $oauth2_proxy_segment for staging
44
# grab okta oauth token from browser cookie for that
55
# output=`curl --cookie $oauth2_proxy_segment -sS -H -v -o /dev/null -IL -w "%{http_code}" ${url}`
6+
echo "Testing redirects..."
67

7-
while read p; do
8-
url="https://segment.build${p}"
8+
check_link () {
9+
url="https://segment.com$1"
910
output=`curl -sS -H -v -o /dev/null -IL -w "%{http_code}" ${url}`
1011
if [ "$output" != "200" ]; then
11-
echo $p $output
12+
echo $1 $output
1213
fi
14+
}
15+
16+
while read p; do
17+
check_link $p &
1318
done < tests/redirects/testPaths.txt
19+
20+
wait
21+
exit 1

tests/redirects/testPaths.txt

+1-22
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,14 @@
55
/docs/connections/destinations/catalog/iron.io/
66
/docs/connections/destinations/catalog/keen-io
77
/docs/connections/destinations/catalog/keen-io/
8-
/docs/connections/destinations/catalog/optimizely-full-stack/index.md
98
/docs/connections/destinations/catalog/optimizely/
109
/docs/connections/destinations/catalog/optimizelyx/
11-
/docs/connections/destinations/catalog/optimizelyx/index.md
1210
/docs/connections/destinations/catalog/promoter.io/
13-
/docs/connections/destinations/catalog/survicate/[email protected]
1411
/docs/connections/destinations/catalog/trak.io/
1512
/docs/connections/destinations/catalog/tray.io/
16-
/docs/connections/destinations/catalog/webengage/[email protected]
17-
/docs/connections/sources/catalog/cloud-apps/aircall/[email protected]
1813
/docs/connections/sources/catalog/cloud-apps/appboy/
19-
/docs/connections/sources/catalog/cloud-apps/delighted/[email protected]
20-
/docs/connections/sources/catalog/libraries/mobile/ios/install-the-sdk
2114
/docs/connections/sources/catalog/libraries/server
2215
/docs/connections/sources/catalog/libraries/website/analytics.js
23-
/docs/connections/sources/catalog/libraries/website/cross-domain
24-
/docs/connections/sources/catalog/libraries/website/pixel/
25-
/docs/connections/sources/catalog/libraries/website/plugins/
26-
/docs/connections/sources/catalog/libraries/website/tracking-api
2716
/docs/connections/sources/catalog/mobile/android/quickstart/
2817
/docs/connections/sources/catalog/mobile/ios/quickstart/
2918
/docs/connections/sources/catalog/server/go/quickstart/
@@ -34,9 +23,7 @@
3423
/docs/connections/sources/catalog/server/python/quickstart/
3524
/docs/connections/sources/catalog/server/ruby/quickstart/
3625
/docs/connections/sources/catalog/server/rust/quickstart/
37-
/docs/connections/sources/custom/
3826
/docs/connections/sources/iterable/
39-
/docs/connections/spec/reset/
4027
/docs/connections/warehouses/add-users/
4128
/docs/connections/warehouses/catalog/azuresqldb/
4229
/docs/connections/warehouses/warehouse-faqs/
@@ -61,7 +48,6 @@
6148
/docs/destinations/radiumone-connect
6249
/docs/destinations/spinnakr
6350
/docs/destinations/stitch-data
64-
/docs/destinations/survicate/[email protected]
6551
/docs/destinations/tapstream
6652
/docs/destinations/trak.io/
6753
/docs/destinations/xplenty
@@ -95,24 +81,17 @@
9581
/docs/guides/warehouses/source-slug/
9682
/docs/guides/warehouses/whitelist-ip-addresses
9783
/docs/guides/warehouses/whitelist-ip-addresses/
98-
/docs/integrations/autosend/
99-
/docs/integrations/chartio/
10084
/docs/integrations/customer.io/
10185
/docs/integrations/freshdesk/
10286
/docs/integrations/keen-io/
10387
/docs/integrations/knowtify/
104-
/docs/integrations/looker/
10588
/docs/integrations/marketo/
106-
/docs/integrations/mode/
107-
/docs/integrations/mojn/
108-
/docs/integrations/periscope.io/
10989
/docs/integrations/tableau/
11090
/docs/legal/[email protected]
11191
/docs/personas/trait-and-audience-building/
92+
/docs/asdfasdfasdf/asdf
11293
/docs/protcols/ecommerce-tracking-plan/
11394
/docs/segment.com
114-
/docs/sources/cloud-apps/aircall/[email protected]
115-
/docs/sources/cloud-apps/delighted/[email protected]
11695
/docs/sources/website/guides/
11796
/docs/sources/website/guides/magento
11897
/docs/sources/website/guides/magento/

0 commit comments

Comments
 (0)