Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions docs/devGuide/development/workflow.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,29 @@ To run the test script, use: `npm run test`
If you only want to run tests for one of the packages (`packages/*`), simply switch into the appropriate directory and use `npm run test` as well!
</box>

<box type="info" seamless>

When running `npm run test`, you may see errors in the console. Some of these errors are **expected** as part of the test cases.
Check the test logs for messages like:

```
info: The following 2 errors are expected to be thrown during the test run:
info: 1: No such segment '#doesNotExist' in file: markbind\packages\core\include.md
info: 2: Cyclic reference detected.
```

If an error is listed there, it's safe to ignore.
</box>

#### Updating and writing tests

<box type="warning" seamless>

If you're adding tests that are expected to log errors to the console, make sure to **update the corresponding info messages** in the test logs.

This ensures that expected errors are properly listed and avoids confusion during test runs.
</box>

##### Updating unit tests

Our unit tests perform fast, stable, and comprehensive checks on important behaviors of our classes and functions. Some existing tests can be found in the `packages/cli/test/unit` and `packages/core/test/unit` directory. Where appropriate, unit tests should be added/modified to account for any new/changed functionality.
Expand Down
14 changes: 14 additions & 0 deletions packages/cli/test/functional/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ const { compare } = require('./testUtil/compare');

const { cleanupConvert } = require('./testUtil/cleanup');

const logger = require('../../../core/src/utils/logger');

const {
testSites,
testConvertSites,
Expand All @@ -29,6 +31,18 @@ const execOptions = {
stdio: ['inherit', 'inherit', 'inherit'],
};

const expectedErrors = ["URLs are not allowed in the 'src' attribute"];

logger.info(
`The following ${
expectedErrors.length === 1 ? 'error is' : 'errors are'
} expected to be thrown during the test run:`,
);

expectedErrors.forEach((error, index) => {
logger.info(`${index + 1}: ${error}`);
});

testSites.forEach((siteName) => {
console.log(`Running ${siteName} tests`);
try {
Expand Down
25 changes: 16 additions & 9 deletions packages/core/src/html/includePanelProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function _checkAndWarnFileExists(element: MbNode, context: Context, actualFilePa
});
const error = new Error(
`No such file: ${actualFilePath}\nMissing reference in ${context.cwf}`);
logger.error(error);
logger.error(error.message);

createErrorNode(element, error);
return false;
Expand Down Expand Up @@ -187,7 +187,7 @@ export function processInclude(node: MbNode, context: Context, pageSources: Page
getNextFootnodeNumber: () => number = buildGetNextFootnodeNumber()): Context {
if (_.isEmpty(node.attribs.src)) {
const error = new Error(`Empty src attribute in include in: ${context.cwf}`);
logger.error(error);
logger.error(error.message);
cheerio(node).replaceWith(createErrorNode(node, error));
return context;
}
Expand Down Expand Up @@ -272,7 +272,7 @@ export function processInclude(node: MbNode, context: Context, pageSources: Page
if (actualContentOrNull === null && !isOptional) {
const error = new Error(`No such segment '${hash}' in file: ${actualFilePath}\n`
+ `Missing reference in ${context.cwf}`);
logger.error(error);
logger.error(error.message);

actualContent = cheerio.html(createErrorNode(node, error));
} else if (actualContentOrNull === '') {
Expand All @@ -294,7 +294,7 @@ export function processInclude(node: MbNode, context: Context, pageSources: Page

if (childContext.hasExceededMaxCallstackSize()) {
const error = new CyclicReferenceError(childContext.callStack);
logger.error(error);
logger.error(error.message);
cheerio(node).replaceWith(createErrorNode(node, error));
return context;
}
Expand All @@ -318,8 +318,8 @@ export function processPopoverSrc(node: MbNode, context: Context, pageSources: P
}

if (_.isEmpty(node.attribs.src)) {
const error = new Error(`Empty src attribute in include in: ${context.cwf}`);
logger.error(error);
const error = new Error(`Empty src attribute in popover in: ${context.cwf}`);
logger.error(error.message);
cheerio(node).replaceWith(createErrorNode(node, error));
return context;
}
Expand All @@ -335,7 +335,14 @@ export function processPopoverSrc(node: MbNode, context: Context, pageSources: P
// No need to process url contents
if (isUrl) {
const error = new Error('URLs are not allowed in the \'src\' attribute');
logger.error(error);

logger.error(`${error.message}
File: ${context.cwf}
URL provided: ${node.attribs.src}

Please check the \`src\` attribute in the popover element.
Ensure it doesn't contain a URL (e.g., "http://www.example.com").`);

cheerio(node).replaceWith(createErrorNode(node, error));
return context;
}
Expand Down Expand Up @@ -369,7 +376,7 @@ export function processPopoverSrc(node: MbNode, context: Context, pageSources: P
if (actualContent === '') {
const error = new Error(`No such segment '${hash}' in file: ${actualFilePath}\n`
+ `Missing reference in ${context.cwf}`);
logger.error(error);
logger.error(error.message);

cheerio(node).replaceWith(createErrorNode(node, error));

Expand All @@ -384,7 +391,7 @@ export function processPopoverSrc(node: MbNode, context: Context, pageSources: P

if (childContext.hasExceededMaxCallstackSize()) {
const error = new CyclicReferenceError(childContext.callStack);
logger.error(error);
logger.error(error.message);
cheerio(node).replaceWith(createErrorNode(node, error));
return context;
}
Expand Down
Loading