docsify/test/unit/core-util.test.js
Joe Pea 62d756c447 refactor: convert to ES Modules and remove traces of CommonJS except in Rollup config because some dependencies are still CommonJS
BREAKING: The new project layout might break in some tooling setups.

We've added an exports field to `package.json` to specify where
statements like `import ... from 'docsify'` will import from, and left
the `main` and `unpkg` fields as-is for backwards compatibility with the
global <script> import method. Most people who use a non-module
`<script>` tag to import Docsify will not notice a difference. Anyone
else who is importing Docsify into a specilized build setup using
`import` statements has a chance of being broken, so we've marked this
as BREAKING.
2023-06-29 19:02:08 -07:00

76 lines
2.0 KiB
JavaScript

import { isExternal } from '../../src/core/util/index.js';
// Core util
// -----------------------------------------------------------------------------
describe('core/util', () => {
// isExternal()
// ---------------------------------------------------------------------------
describe('isExternal()', () => {
// cases non external
test('non external local url with one /', () => {
const result = isExternal(`/${location.host}/docsify/demo.md`);
expect(result).toBeFalsy();
});
test('non external local url with two //', () => {
const result = isExternal(`//${location.host}/docsify/demo.md`);
expect(result).toBeFalsy();
});
test('non external local url with three ///', () => {
const result = isExternal(`///${location.host}/docsify/demo.md`);
expect(result).toBeFalsy();
});
test('non external local url with more /', () => {
const result = isExternal(
`//////////////////${location.host}/docsify/demo.md`
);
expect(result).toBeFalsy();
});
test('non external url with one /', () => {
const result = isExternal('/example.github.io/docsify/demo.md');
expect(result).toBeFalsy();
});
// cases is external
test('external url with two //', () => {
const result = isExternal('/docsify/demo.md');
expect(result).toBeFalsy();
});
test('external url with three ///', () => {
const result = isExternal('///example.github.io/docsify/demo.md');
expect(result).toBeTruthy();
});
test('external url with more /', () => {
const result = isExternal(
'//////////////////example.github.io/docsify/demo.md'
);
expect(result).toBeTruthy();
});
test('external url with one \\', () => {
const result = isExternal('/\\example.github.io/docsify/demo.md');
expect(result).toBeTruthy();
});
test('external url with two \\', () => {
const result = isExternal('/\\\\example.github.io/docsify/demo.md');
expect(result).toBeTruthy();
});
});
});