mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-16 18:46:57 +02:00
Fix CSS tests (#839)
* Fix CSS tests * Revamp * - * fix failing test * add test for minifyCss with fixtures & snapshot * remove unintended addition * simplify the test.css
This commit is contained in:
parent
8cd4b4fca6
commit
4267337fb0
9 changed files with 178 additions and 88 deletions
|
@ -5,7 +5,6 @@
|
|||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
const cssnano = require('cssnano');
|
||||
const filepath = require('filepath');
|
||||
const fm = require('front-matter');
|
||||
const fs = require('fs-extra');
|
||||
|
@ -15,6 +14,7 @@ const shell = require('shelljs');
|
|||
|
||||
const CWD = process.cwd();
|
||||
|
||||
const utils = require('../server/utils');
|
||||
const siteConfig = require(CWD + '/website/siteConfig.js');
|
||||
const buildDir = CWD + '/website/build';
|
||||
const docsDir = CWD + '/docs';
|
||||
|
@ -34,82 +34,85 @@ 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,
|
||||
outputHTMLFiles,
|
||||
inputAssetsFiles,
|
||||
outputAssetsFiles,
|
||||
] = results;
|
||||
describe('Build files', () => {
|
||||
beforeEach(() => {
|
||||
shell.cd(CWD);
|
||||
});
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
clearBuildFolder();
|
||||
});
|
||||
|
||||
test('Build folder exists', function() {
|
||||
return fs.stat(buildDir).then(function(status) {
|
||||
expect(status.isDirectory()).toBeTruthy();
|
||||
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,
|
||||
outputHTMLFiles,
|
||||
inputAssetsFiles,
|
||||
outputAssetsFiles,
|
||||
] = results;
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
test('Generated HTML for each Markdown resource', function() {
|
||||
let metadata = [];
|
||||
outputHTMLFiles.forEach(function(file) {
|
||||
const path = filepath.create(file);
|
||||
metadata.push(path.basename());
|
||||
afterAll(() => {
|
||||
clearBuildFolder();
|
||||
});
|
||||
inputMarkdownFiles.forEach(function(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('Build folder exists', function() {
|
||||
return fs.stat(buildDir).then(function(status) {
|
||||
expect(status.isDirectory()).toBeTruthy();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
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, outputFile] = results;
|
||||
inputFiles.forEach(async function(file) {
|
||||
const contents = fs.readFileSync(file, 'utf8');
|
||||
const {css} = await cssnano.process(contents, {}, {preset: 'default'});
|
||||
expect(outputFile).toContain(css);
|
||||
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 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', async function() {
|
||||
const inputFiles = await glob(staticCSSDir + '/*.css');
|
||||
const combinedCSSFile =
|
||||
buildDir + '/' + siteConfig.projectName + '/css/main.css';
|
||||
const fileContents = await Promise.all(
|
||||
[combinedCSSFile, ...inputFiles].map(file => fs.readFile(file, 'utf8'))
|
||||
);
|
||||
|
||||
const [outputFileContent, ...inputFileContents] = fileContents;
|
||||
const minifiedCssFiles = await Promise.all(
|
||||
inputFileContents.map(utils.minifyCss)
|
||||
);
|
||||
|
||||
minifiedCssFiles.forEach(fileContent => {
|
||||
expect(outputFileContent).toContain(fileContent);
|
||||
});
|
||||
});
|
||||
|
||||
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());
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
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());
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue