fix(v2): fix chokidar/watcher does not trigger reload on windows (#1943)

* fix(v2): fix chokidar/watcher does not trigger reload on windows

* nits

* nits

* stronger test
This commit is contained in:
Endi 2019-11-06 22:52:40 +07:00 committed by Yangshun Tay
parent ff83e6f8bc
commit baa884fe2e
7 changed files with 35 additions and 4 deletions

View file

@ -7,11 +7,13 @@
import path from 'path';
import {validate} from 'webpack';
import {isMatch} from 'picomatch';
import fs from 'fs-extra';
import pluginContentDocs from '../index';
import {loadContext} from '@docusaurus/core/src/server/index';
import {applyConfigureWebpack} from '@docusaurus/core/src/webpack/utils';
import {RouteConfig} from '@docusaurus/types';
import {posixPath} from '@docusaurus/utils';
const createFakeActions = (routeConfigs: RouteConfig[], contentDir) => {
return {
@ -87,7 +89,26 @@ describe('simple website', () => {
test('getPathToWatch', () => {
const pathToWatch = plugin.getPathsToWatch();
expect(pathToWatch).not.toEqual([]);
const matchPattern = pathToWatch.map(filepath =>
posixPath(path.relative(siteDir, filepath)),
);
expect(matchPattern).not.toEqual([]);
expect(matchPattern).toMatchInlineSnapshot(`
Array [
"docs/**/*.{md,mdx}",
"sidebars.json",
]
`);
expect(isMatch('docs/hello.md', matchPattern)).toEqual(true);
expect(isMatch('docs/hello.mdx', matchPattern)).toEqual(true);
expect(isMatch('docs/foo/bar.md', matchPattern)).toEqual(true);
expect(isMatch('docs/hello.js', matchPattern)).toEqual(false);
expect(isMatch('docs/super.mdl', matchPattern)).toEqual(false);
expect(isMatch('docs/mdx', matchPattern)).toEqual(false);
expect(isMatch('sidebars.json', matchPattern)).toEqual(true);
expect(isMatch('versioned_docs/hello.md', matchPattern)).toEqual(false);
expect(isMatch('hello.md', matchPattern)).toEqual(false);
expect(isMatch('super/docs/hello.md', matchPattern)).toEqual(false);
});
test('configureWebpack', async () => {