|
@ -1,61 +1,52 @@ |
|
|
/* eslint-disable no-await-in-loop */ |
|
|
/* eslint-disable no-await-in-loop */ |
|
|
/* eslint-disable no-restricted-syntax */ |
|
|
/* eslint-disable no-restricted-syntax */ |
|
|
const fetch = require('isomorphic-fetch'); |
|
|
import cheerio from 'cheerio'; |
|
|
const { join } = require('path'); |
|
|
import { globSync } from 'glob'; |
|
|
const cheerio = require('cheerio'); |
|
|
import type http from 'http'; |
|
|
const glob = require('glob'); |
|
|
import { createServer } from 'http-server'; |
|
|
const uniq = require('lodash/uniq'); |
|
|
import type https from 'https'; |
|
|
const { createServer } = require('http-server'); |
|
|
import fetch from 'isomorphic-fetch'; |
|
|
|
|
|
import uniq from 'lodash/uniq'; |
|
|
|
|
|
import { join } from 'path'; |
|
|
|
|
|
|
|
|
const components = uniq( |
|
|
const components = uniq( |
|
|
glob |
|
|
globSync('components/!(overview)/*.md', { cwd: join(process.cwd()), dot: false }).map((path) => |
|
|
.globSync('components/!(overview)/*.md', { |
|
|
path.replace(/(\/index)?((\.zh-cn)|(\.en-us))?\.md$/i, ''), |
|
|
cwd: join(process.cwd()), |
|
|
), |
|
|
dot: false, |
|
|
|
|
|
}) |
|
|
|
|
|
.map((path) => path.replace(/(\/index)?((\.zh-cn)|(\.en-us))?\.md$/i, '')), |
|
|
|
|
|
); |
|
|
); |
|
|
|
|
|
|
|
|
describe('site test', () => { |
|
|
describe('site test', () => { |
|
|
let server; |
|
|
let server: http.Server | https.Server; |
|
|
const port = 3000; |
|
|
const port = 3000; |
|
|
const render = async (path) => { |
|
|
const render = async (path: string) => { |
|
|
const resp = await fetch(`http://127.0.0.1:${port}${path}`).then(async (res) => { |
|
|
const resp = await fetch(`http://127.0.0.1:${port}${path}`).then(async (res) => { |
|
|
const html = await res.text(); |
|
|
const html = await res.text(); |
|
|
const $ = cheerio.load(html, { decodeEntities: false, recognizeSelfClosing: true }); |
|
|
const $ = cheerio.load(html, { decodeEntities: false, recognizeSelfClosing: true }); |
|
|
return { |
|
|
return { html, status: res.status, $ }; |
|
|
html, |
|
|
|
|
|
status: res.status, |
|
|
|
|
|
$, |
|
|
|
|
|
}; |
|
|
|
|
|
}); |
|
|
}); |
|
|
return resp; |
|
|
return resp; |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
const handleComponentName = (name) => { |
|
|
const handleComponentName = (name: string) => { |
|
|
const componentName = name.split('/')[1]; |
|
|
const [, componentName] = name.split('/'); |
|
|
return componentName.toLowerCase().replace('-cn', '').replace('-', ''); |
|
|
return componentName.toLowerCase().replace('-cn', '').replace('-', ''); |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
const expectComponent = async (component) => { |
|
|
const expectComponent = async (component: string) => { |
|
|
const { status, $ } = await render(`/${component}/`); |
|
|
const { status, $ } = await render(`/${component}/`); |
|
|
expect(status).toBe(200); |
|
|
expect(status).toBe(200); |
|
|
expect($('h1').text().toLowerCase()).toMatch(handleComponentName(component)); |
|
|
expect($('h1').text().toLowerCase()).toMatch(handleComponentName(component)); |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
beforeAll(() => { |
|
|
beforeAll(() => { |
|
|
server = createServer({ |
|
|
server = createServer({ root: join(process.cwd(), '_site') }); |
|
|
root: join(process.cwd(), '_site'), |
|
|
|
|
|
}); |
|
|
|
|
|
server.listen(port); |
|
|
server.listen(port); |
|
|
// eslint-disable-next-line no-console
|
|
|
// eslint-disable-next-line no-console
|
|
|
console.log('site static server run: http://localhost:3000'); |
|
|
console.log('site static server run: http://localhost:3000'); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
afterAll(() => { |
|
|
afterAll(() => { |
|
|
if (server) { |
|
|
server?.close(); |
|
|
server.close(); |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
it('Basic Pages en', async () => { |
|
|
it('Basic Pages en', async () => { |
|
@ -89,7 +80,6 @@ describe('site test', () => { |
|
|
it(`Component ${component} zh Page`, async () => { |
|
|
it(`Component ${component} zh Page`, async () => { |
|
|
await expectComponent(`${component}-cn`); |
|
|
await expectComponent(`${component}-cn`); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
it(`Component ${component} en Page`, async () => { |
|
|
it(`Component ${component} en Page`, async () => { |
|
|
await expectComponent(component); |
|
|
await expectComponent(component); |
|
|
}); |
|
|
}); |