egg/test/doc.test.js
fengmk2 9bf5f22bfa
feat: use utility@2 (#5312)
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit


- **Chores**
	- Updated Node.js versions in CI workflows to include version 22.
- Removed an unused parameter in the release workflow to streamline
operations.

- **Refactor**
- Improved code efficiency in HTTP client by using destructured imports.

- **Documentation**
- Updated software dependencies in `package.json` to enhance
functionality and compatibility.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2024-05-08 15:36:27 +08:00

42 lines
1.4 KiB
JavaScript

'use strict';
const path = require('path');
const findlinks = require('findlinks');
const assert = require('assert');
const runscript = require('runscript');
const utils = require('./utils');
const puppeteer = require('puppeteer');
describe('test/doc.test.js', () => {
/**
* This unit test is ONLY working for the latest nodejs version (v18.0.0)
* or higher version, bcoz on windows, it takes quite a lot of time
* to generate the whole doc. We only need some of the test cases to check
* whether the links inside the doc gets fine or not.
*/
it('should have no broken urls (based on non-windows platform and node\'s version >=18)', async function() {
const mainNodejsVersion = parseInt(process.versions.node.split('.')[0]);
if (process.platform === 'linux' && mainNodejsVersion >= 18) {
const cwd = path.dirname(__dirname);
const dumi = path.join(cwd, 'node_modules', '.bin', 'dumi');
await runscript(`cross-env NODE_OPTIONS=--openssl-legacy-provider APP_ROOT=./site ${dumi} build`,
{
cwd,
});
const app = utils.cluster({
baseDir: 'apps/docapp',
});
app.coverage(false);
await app.ready();
const result = await findlinks({ src: app.url, logger: console, puppeteer });
if (result.fail !== 0) console.log(result);
assert(result.fail === 0);
app.close();
} else {
this.skip();
}
}).timeout(10 * 60 * 1000);
});