mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-01 03:08:17 +02:00
Add first set of docusaurus-build tests using Jest (#259)
* Add Prettier formatting to source files and example files, and check that Prettier formatting is maintained on PRs * Remove trailing-comma as we are using Node 6 on Circle * Use latest Node 6 LTS version in Circle * Initial test suite * Rename test to match original file * restore test files * Remove yarn.lock from pull request. Will run it again in a separate commit
This commit is contained in:
parent
8ec4a6bfe5
commit
9dadb3578c
4 changed files with 122 additions and 6 deletions
|
@ -31,7 +31,7 @@ defaults: &defaults
|
||||||
|
|
||||||
version: 2
|
version: 2
|
||||||
jobs:
|
jobs:
|
||||||
test-website:
|
tests:
|
||||||
<<: *defaults
|
<<: *defaults
|
||||||
steps:
|
steps:
|
||||||
- checkout
|
- checkout
|
||||||
|
@ -42,7 +42,10 @@ jobs:
|
||||||
name: Check Prettier
|
name: Check Prettier
|
||||||
command: yarn ci-check
|
command: yarn ci-check
|
||||||
- run:
|
- run:
|
||||||
name: Test Build Static Website
|
name: Run Test Suites
|
||||||
|
command: yarn test
|
||||||
|
- run:
|
||||||
|
name: Test Static Website Builds
|
||||||
command: cd website && yarn run build
|
command: cd website && yarn run build
|
||||||
|
|
||||||
deploy-website:
|
deploy-website:
|
||||||
|
@ -99,11 +102,11 @@ workflows:
|
||||||
|
|
||||||
website:
|
website:
|
||||||
jobs:
|
jobs:
|
||||||
- test-website:
|
- tests:
|
||||||
filters: *filter-ignore-gh-pages
|
filters: *filter-ignore-gh-pages
|
||||||
- deploy-website:
|
- deploy-website:
|
||||||
requires:
|
requires:
|
||||||
- test-website
|
- tests
|
||||||
filters: *filter-only-master
|
filters: *filter-only-master
|
||||||
|
|
||||||
deploy:
|
deploy:
|
||||||
|
|
0
.watchmanconfig
Normal file
0
.watchmanconfig
Normal file
107
lib/__tests__/build-files.tests.js
Normal file
107
lib/__tests__/build-files.tests.js
Normal file
|
@ -0,0 +1,107 @@
|
||||||
|
const filepath = require('filepath');
|
||||||
|
const fm = require('front-matter');
|
||||||
|
const fs = require('fs-extra');
|
||||||
|
const glob = require('glob-promise');
|
||||||
|
const rimraf = require('rimraf');
|
||||||
|
const shell = require('shelljs');
|
||||||
|
|
||||||
|
const CWD = process.cwd();
|
||||||
|
|
||||||
|
const siteConfig = require(CWD + '/website/siteConfig.js');
|
||||||
|
const buildDir = CWD + '/website/build';
|
||||||
|
const docsDir = CWD + '/docs';
|
||||||
|
const staticCSSDir = CWD + '/website/static/css';
|
||||||
|
|
||||||
|
let inputMarkdownFiles = [];
|
||||||
|
let inputAssetsFiles = [];
|
||||||
|
let outputHTMLFiles = [];
|
||||||
|
let outputAssetsFiles = [];
|
||||||
|
|
||||||
|
function generateSite() {
|
||||||
|
shell.cd('website');
|
||||||
|
shell.exec('yarn build');
|
||||||
|
}
|
||||||
|
|
||||||
|
function clearBuildFolder() {
|
||||||
|
return rimraf(buildDir);
|
||||||
|
}
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
shell.cd(CWD);
|
||||||
|
});
|
||||||
|
|
||||||
|
beforeAll(() => {
|
||||||
|
generateSite();
|
||||||
|
return Promise.all([
|
||||||
|
glob(docsDir + '/**/*.md'),
|
||||||
|
glob(buildDir + '/' + siteConfig.projectName + '/docs/*.html'),
|
||||||
|
glob(docsDir + '/assets/*'),
|
||||||
|
glob(buildDir + '/' + siteConfig.projectName + '/img/*'),
|
||||||
|
]).then(function(results) {
|
||||||
|
inputMarkdownFiles = results[0];
|
||||||
|
outputHTMLFiles = results[1];
|
||||||
|
inputAssetsFiles = results[2];
|
||||||
|
outputAssetsFiles = results[3];
|
||||||
|
return;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
function afterAll() {
|
||||||
|
clearBuildFolder();
|
||||||
|
}
|
||||||
|
|
||||||
|
test('Build folder exists', function() {
|
||||||
|
return fs.stat(buildDir).then(function(status) {
|
||||||
|
expect(status.isDirectory()).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Generated HTML for each Markdown resource', function() {
|
||||||
|
let metadata = [];
|
||||||
|
outputHTMLFiles.forEach(function(file) {
|
||||||
|
const path = filepath.create(file);
|
||||||
|
metadata.push(path.basename());
|
||||||
|
});
|
||||||
|
inputMarkdownFiles.forEach(function(file) {
|
||||||
|
const path = filepath.create(file);
|
||||||
|
const data = fs.readFileSync(file, 'utf8');
|
||||||
|
const frontmatter = fm(data);
|
||||||
|
expect(metadata).toContain(frontmatter.attributes.id + '.html');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Generated table of contents', function() {
|
||||||
|
outputHTMLFiles.forEach(function(file) {
|
||||||
|
const fileContents = fs.readFileSync(file, 'utf8');
|
||||||
|
expect(fileContents).not.toContain('<AUTOGENERATED_TABLE_OF_CONTENTS>');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Concatenated CSS files', function() {
|
||||||
|
return Promise.all([
|
||||||
|
glob(staticCSSDir + '/*.css'),
|
||||||
|
fs.readFile(
|
||||||
|
buildDir + '/' + siteConfig.projectName + '/css/main.css',
|
||||||
|
'utf8'
|
||||||
|
),
|
||||||
|
]).then(function(results) {
|
||||||
|
const inputFiles = results[0];
|
||||||
|
const outputFile = results[1];
|
||||||
|
inputFiles.forEach(function(file) {
|
||||||
|
const contents = fs.readFileSync(file, 'utf8');
|
||||||
|
expect(outputFile).toContain(contents);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Copied assets from /docs/assets', function() {
|
||||||
|
let metadata = [];
|
||||||
|
outputAssetsFiles.forEach(function(file) {
|
||||||
|
const path = filepath.create(file);
|
||||||
|
metadata.push(path.basename());
|
||||||
|
});
|
||||||
|
inputAssetsFiles.forEach(function(file) {
|
||||||
|
const path = filepath.create(file);
|
||||||
|
expect(metadata).toContain(path.basename());
|
||||||
|
});
|
||||||
|
});
|
10
package.json
10
package.json
|
@ -20,7 +20,8 @@
|
||||||
"nit:source": "prettier --config .prettierrc --list-different \"lib/**/*.js\"",
|
"nit:source": "prettier --config .prettierrc --list-different \"lib/**/*.js\"",
|
||||||
"nit:examples": "prettier --config .prettierrc --list-different \"examples/**/*.js\"",
|
"nit:examples": "prettier --config .prettierrc --list-different \"examples/**/*.js\"",
|
||||||
"prettier": "yarn format:source && yarn format:examples",
|
"prettier": "yarn format:source && yarn format:examples",
|
||||||
"prettier:diff": "yarn nit:source && yarn nit:examples"
|
"prettier:diff": "yarn nit:source && yarn nit:examples",
|
||||||
|
"test": "jest"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"babel-preset-env": "^1.6.0",
|
"babel-preset-env": "^1.6.0",
|
||||||
|
@ -59,6 +60,11 @@
|
||||||
"docusaurus-feed": "./lib/generate-feed.js"
|
"docusaurus-feed": "./lib/generate-feed.js"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"prettier": "^1.9.1"
|
"prettier": "^1.9.1",
|
||||||
|
"filepath": "^1.1.0",
|
||||||
|
"front-matter": "^2.3.0",
|
||||||
|
"glob-promise": "^3.3.0",
|
||||||
|
"jest": "^21.2.1",
|
||||||
|
"rimraf": "^2.6.2"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue