forked from Codecademy/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add tests to verify content file structure
- Loading branch information
1 parent
00f82d3
commit 55b590d
Showing
10 changed files
with
4,480 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
version: 2.1 | ||
|
||
orbs: | ||
cypress: cypress-io/[email protected] | ||
|
||
references: | ||
default_env: &default_env | ||
docker: | ||
- image: cypress/base:12.14.0 | ||
working_directory: ~/repo | ||
|
||
repo_cache_key_1: &repo_cache_key_1 v1-cypress-repo-{{ arch}}-{{ .Branch }}-{{ .Revision }} | ||
repo_cache_key_2: &repo_cache_key_2 v1-cypress-repo-{{ arch}}-{{ .Branch }} | ||
repo_cache_key_3: &repo_cache_key_3 v1-cypress-repo-{{ arch}} | ||
|
||
restore_repo: &restore_repo | ||
restore_cache: | ||
keys: | ||
- *repo_cache_key_1 | ||
- *repo_cache_key_2 | ||
- *repo_cache_key_3 | ||
|
||
jobs: | ||
checkout_code: | ||
<<: *default_env | ||
steps: | ||
- *restore_repo | ||
- checkout | ||
- run: npx [email protected] --production=false --frozen-lockfile | ||
- save_cache: | ||
key: *repo_cache_key_1 | ||
paths: | ||
- . | ||
|
||
verify_formatting: | ||
<<: *default_env | ||
steps: | ||
- *restore_repo | ||
- run: | ||
name: Verify Prettier | ||
command: yarn prettier:verify | ||
|
||
verify_compile: | ||
<<: *default_env | ||
steps: | ||
- *restore_repo | ||
- run: | ||
name: Verify Typescript | ||
command: yarn compile | ||
|
||
verify_lint: | ||
<<: *default_env | ||
steps: | ||
- *restore_repo | ||
- run: | ||
name: Verify ESLint | ||
command: yarn lint --format junit --output-file /tmp/test-results/eslint.xml | ||
- store_test_results: | ||
path: /tmp/test-results | ||
|
||
tests: | ||
<<: *default_env | ||
parallelism: 4 | ||
resource_class: large | ||
steps: | ||
- *restore_repo | ||
- run: | ||
name: Run test suite | ||
command: yarn test | ||
|
||
workflows: | ||
version: 2 | ||
test: | ||
jobs: | ||
- checkout_code | ||
- verify_compile: | ||
requires: | ||
- checkout_code | ||
- verify_lint: | ||
requires: | ||
- checkout_code | ||
- verify_formatting: | ||
requires: | ||
- checkout_code | ||
- tests: | ||
requires: | ||
- checkout_code |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"extends": ["@codecademy/eslint-config"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,9 @@ | ||
.DS_Store | ||
node_modules | ||
package-lock.json | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
*.swp | ||
*.swo | ||
tmp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules | ||
yarn.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = require('@codecademy/prettier-config'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
|
||
describe('Codecademy Docs Content', () => { | ||
it('adheres to content file structure', () => { | ||
// file names can only contain alphanumerics and hyphens | ||
const validateName = (pathName: string, name: string) => { | ||
const filteredName = name.replace(/[^A-Za-z0-9.-]/g, ''); | ||
|
||
// format so that test failures are more helpful | ||
if (filteredName !== name) { | ||
expect(`${pathName} - file name must only include alphanumerics or -`).toBe(''); | ||
} | ||
}; | ||
|
||
// nodes can have n directories of children and at most one .md file with the same name as its parent directory | ||
const checkNode = (nodePath: string) => { | ||
const children = fs.readdirSync(nodePath); | ||
|
||
children.forEach((child) => { | ||
const childPath = path.join(nodePath, child); | ||
validateName(childPath, child); | ||
|
||
if (fs.statSync(childPath).isDirectory()) { | ||
checkChild(childPath); | ||
} else { | ||
const nodeName = nodePath.split('/').slice(-1)[0]; | ||
expect(childPath).toBe(path.join(nodePath, `${nodeName}.md`)); | ||
} | ||
}); | ||
}; | ||
|
||
// children can only be directories of nodes | ||
const checkChild = (childPath: string) => { | ||
const nodes = fs.readdirSync(childPath); | ||
|
||
nodes.forEach((node) => { | ||
const nodePath = path.join(childPath, node); | ||
validateName(nodePath, node); | ||
|
||
// format so that test failures are more helpful | ||
if(!fs.statSync(nodePath).isDirectory()) { | ||
expect(`${nodePath} - expected a directory but got a file`).toBe(''); | ||
} | ||
checkNode(nodePath); | ||
}); | ||
}; | ||
|
||
checkChild(path.join(__dirname, 'content')); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module.exports = { | ||
preset: 'ts-jest', | ||
testEnvironment: 'node', | ||
clearMocks: true, | ||
testMatch: ['**/*test.ts'], | ||
testPathIgnorePatterns: ['<rootDir>/[/\\\\]node_modules[/\\\\]'], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"name": "CodecademyDocs", | ||
"devDependencies": { | ||
"@codecademy/eslint-config": "5.0.0", | ||
"@codecademy/prettier-config": "^0.1.10", | ||
"@codecademy/tsconfig": "^0.2.0", | ||
"@types/jest": "^26.0.24", | ||
"@types/node": "^16.4.3", | ||
"eslint": "^7.25.0", | ||
"jest": "^27.0.6", | ||
"prettier": "^2.2.1", | ||
"ts-jest": "^27.0.4", | ||
"typescript": "^4.2.4" | ||
}, | ||
"scripts": { | ||
"compile": "tsc --noEmit", | ||
"format": "prettier --ignore-path .prettierignore --write", | ||
"format:verify": "prettier \"./**.ts\" --list-different", | ||
"lint": "eslint \"./**.ts\" --max-warnings 0", | ||
"test": "jest" | ||
}, | ||
"version": "1.0.0" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"extends": "@codecademy/tsconfig", | ||
"compilerOptions": { | ||
"allowJs": true, | ||
"baseUrl": ".", | ||
"isolatedModules": true, | ||
"lib": ["dom", "dom.iterable", "esnext"], | ||
"noEmit": true, | ||
"noImplicitReturns": true, | ||
"module": "commonjs", | ||
"moduleResolution": "node", | ||
"resolveJsonModule": true | ||
}, | ||
"exclude": ["node_modules"], | ||
"include": ["**/*.ts"] | ||
} |
Oops, something went wrong.