Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(test): modify source-code-build test case about enable ts-loader #4282

Merged
merged 1 commit into from
Jul 24, 2023
Merged
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
fix(test): modify source-code-build test case about enable ts-loader
  • Loading branch information
targeral committed Jul 24, 2023
commit 64f568d3460f777d55841f0ec2591afc3cd9553a
8 changes: 5 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"@modern-js/runtime": "workspace:*",
"react": "^18",
"react-dom": "^18",
"@source-code-build/components": "workspace:*",
"@source-code-build/common": "workspace:*",
"antd": "^5"
},
"devDependencies": {
Expand Down
6 changes: 4 additions & 2 deletions tests/integration/source-code-build/app-ts-loader/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { Card } from '@source-code-build/components';
import { VERSION, type Plugin } from '@source-code-build/common';
import { Button } from 'antd';
import './App.css';

export const plugin = { some: true } as Plugin;

const App = () => (
<div className="container">
<main>
<Card title="App" content="hello world"></Card>
{VERSION}
<Button>click</Button>
</main>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"include": ["src", "shared", "config"],
"references": [
{
"path": "../components/tsconfig.json"
"path": "../common/tsconfig.json"
}
]
}
30 changes: 30 additions & 0 deletions tests/integration/source-code-build/common/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name": "@source-code-build/common",
"private": true,
"version": "2.9.0",
"types": "./src/index.ts",
"source": "./src/index.ts",
"main": "./dist/lib/index.js",
"module": "./dist/es/index.js",
"exports": {
".": {
"source": "./src/index.ts",
"default": "./dist/es/index.js"
}
},
"typesVersions": {
"*": {
".": [
"./src/index.ts"
]
}
},
"dependencies": {},
"engines": {
"node": ">=14.17.6"
},
"eslintIgnore": [
"node_modules/",
"dist/"
]
}
12 changes: 12 additions & 0 deletions tests/integration/source-code-build/common/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Note

## tsconfig.json

- Require config `"rootDir": "./src"` in `compilerOptions`
- Require config `"composite": true,`
- Require config `"declaration": true,` in `compilerOptions`
- Require config `"declarationDir": "./dist/types"` in `compilerOptions`

## package.json

- `"types"` equal to `"declarationDir` in tsconfig.json
3 changes: 3 additions & 0 deletions tests/integration/source-code-build/common/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './types';

export const VERSION = '1.0.0';
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type Plugin = Record<string, any>;
16 changes: 16 additions & 0 deletions tests/integration/source-code-build/common/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"extends": "@modern-js/tsconfig/base",
"compilerOptions": {
"composite": true,
"declaration": true,
"declarationDir": "./dist/types",
"jsx": "react-jsx",
"baseUrl": "./",
"paths": {
"@/*": ["./src/*"]
},
"rootDir": "src",
"outDir": "./dist"
},
"include": ["src"]
}
49 changes: 10 additions & 39 deletions tests/integration/source-code-build/enable-ts-loader.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@ describe('source build', () => {
let app: any;
let browser: Browser;
let port: number;
let card: {
codeDir: string;
original: string;
};
let utils: {
let common: {
codeDir: string;
original: string;
};
Expand All @@ -30,15 +26,10 @@ describe('source build', () => {
port = await getPort();
app = await launchApp(appDir, port, {});
browser = await puppeteer.launch(launchOptions as any);
const cardCompDir = path.join(__dirname, './components/src/card/index.tsx');
card = {
codeDir: cardCompDir,
original: await fs.readFile(cardCompDir, 'utf8'),
};
const utilsDir = path.join(__dirname, './utils/src/index.ts');
utils = {
codeDir: utilsDir,
original: await fs.readFile(utilsDir, 'utf8'),
const commonIndexPath = path.join(__dirname, './common/src/index.ts');
common = {
codeDir: commonIndexPath,
original: await fs.readFile(commonIndexPath, 'utf8'),
};
});
test('should run successfully', async () => {
Expand All @@ -48,44 +39,24 @@ describe('source build', () => {
await page.goto(`http://localhost:${port}`);
const root = await page.$('#root');
const targetText = await page.evaluate(el => el?.textContent, root);
expect(targetText).toMatch('Card Comp Title: App');
expect(targetText).toMatch('CARD COMP CONTENT:hello world');
expect(targetText).toMatch('1.0.0');
});

test('update component project code', async () => {
const newContent = card.original.replace(/Card Comp/g, 'Card-Comp');
await fs.writeFile(card.codeDir, newContent);
const newContent = common.original.replace(/1.0.0/g, '2.0.0');
await fs.writeFile(common.codeDir, newContent);
await sleep(2000);
const page = await browser.newPage();
await page.goto(`http://localhost:${port}`);
const root = await page.$('#root');
const targetText = await page.evaluate(el => el?.textContent, root);
// console.info('component', targetText);

expect(targetText).toMatch('Card-Comp');
expect(targetText).toMatch('CARD-COMP');
});

test('update utils project code', async () => {
const newContent = `
export const strAdd = (str1: string, str2: string) => {
return 'this is utils' + str1 + str2;
}
`;
await fs.writeFile(utils.codeDir, newContent);
await sleep(2000);
const page = await browser.newPage();
await page.goto(`http://localhost:${port}`);
const root = await page.$('#root');
const targetText = await page.evaluate(el => el?.textContent, root);
// console.info('utils', targetText);
expect(targetText).toMatch('this is utils');
expect(targetText).toMatch('2.0.0');
});

afterAll(async () => {
browser.close();
await killApp(app);
await fs.writeFile(card.codeDir, card.original);
await fs.writeFile(utils.codeDir, utils.original);
await fs.writeFile(common.codeDir, common.original);
});
});
2 changes: 0 additions & 2 deletions tests/integration/source-code-build/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ describe('source build', () => {
await page.goto(`http://localhost:${port}`);
const root = await page.$('#root');
const targetText = await page.evaluate(el => el?.textContent, root);
// console.info('component', targetText);

expect(targetText).toMatch('Card-Comp');
expect(targetText).toMatch('CARD-COMP');
Expand All @@ -78,7 +77,6 @@ describe('source build', () => {
await page.goto(`http://localhost:${port}`);
const root = await page.$('#root');
const targetText = await page.evaluate(el => el?.textContent, root);
// console.info('utils', targetText);
expect(targetText).toMatch('this is utils');
});

Expand Down
12 changes: 12 additions & 0 deletions tests/integration/source-code-build/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"extends": "@modern-js/tsconfig/base",
"compilerOptions": {
"declaration": true,
"jsx": "preserve",
"baseUrl": "./",
"emitDeclarationOnly": true,
"isolatedModules": true,
"paths": {},
"types": ["node", "jest"]
}
}
Loading