-
Notifications
You must be signed in to change notification settings - Fork 369
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(builder): add some e2e test cases (#4105)
* chore(builder): add some e2e test cases * fix: test case
- Loading branch information
Showing
19 changed files
with
268 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
dist-1 | ||
dist-2 | ||
dist-* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
tests/e2e/builder/cases/source/source-exclude/index.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import path from 'path'; | ||
import { expect } from '@modern-js/e2e/playwright'; | ||
import { build } from '@scripts/shared'; | ||
import { webpackOnlyTest } from '@scripts/helper'; | ||
|
||
webpackOnlyTest( | ||
'should not compile specified file when source.exclude', | ||
async () => { | ||
await expect( | ||
build({ | ||
cwd: __dirname, | ||
entry: { index: path.resolve(__dirname, './src/index.js') }, | ||
builderConfig: { | ||
source: { | ||
exclude: [path.resolve(__dirname, './src/test.js')], | ||
}, | ||
security: { | ||
checkSyntax: true, | ||
}, | ||
}, | ||
}), | ||
).rejects.toThrowError('[Syntax Checker]'); | ||
}, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { printLog } from './test'; | ||
|
||
printLog(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export const printLog = () => { | ||
const arr = [1, 2, 3, 4, [5, 6, [7, 8]]]; | ||
console.log(arr, arr.flat()); | ||
}; |
38 changes: 38 additions & 0 deletions
38
tests/e2e/builder/cases/source/source-include/index.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import path from 'path'; | ||
import { expect, test } from '@modern-js/e2e/playwright'; | ||
import { build } from '@scripts/shared'; | ||
import { webpackOnlyTest } from '@scripts/helper'; | ||
|
||
webpackOnlyTest( | ||
'should not compile file which outside of project by default', | ||
async () => { | ||
await expect( | ||
build({ | ||
cwd: __dirname, | ||
entry: { index: path.resolve(__dirname, './src/index.js') }, | ||
builderConfig: { | ||
security: { | ||
checkSyntax: true, | ||
}, | ||
}, | ||
}), | ||
).rejects.toThrowError('[Syntax Checker]'); | ||
}, | ||
); | ||
|
||
test('should compile specified file when source.include', async () => { | ||
await expect( | ||
build({ | ||
cwd: __dirname, | ||
entry: { index: path.resolve(__dirname, './src/index.js') }, | ||
builderConfig: { | ||
source: { | ||
include: [path.resolve(__dirname, '../test.js')], | ||
}, | ||
security: { | ||
checkSyntax: true, | ||
}, | ||
}, | ||
}), | ||
).resolves.toBeDefined(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { printLog } from '../../test'; | ||
|
||
printLog(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export const printLog = () => { | ||
const arr = [1, 2, 3, 4, [5, 6, [7, 8]]]; | ||
console.log(arr, arr.flat()); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import path from 'path'; | ||
import { expect } from '@modern-js/e2e/playwright'; | ||
import { build, getHrefByEntryName } from '@scripts/shared'; | ||
import { webpackOnlyTest } from '@scripts/helper'; | ||
|
||
webpackOnlyTest('security.sri', async ({ page }) => { | ||
const builder = await build({ | ||
cwd: __dirname, | ||
entry: { index: path.resolve(__dirname, './src/index.js') }, | ||
runServer: true, | ||
builderConfig: { | ||
security: { | ||
sri: true, | ||
}, | ||
}, | ||
}); | ||
|
||
const files = await builder.unwrapOutputJSON(); | ||
const htmlFileName = Object.keys(files).find(f => f.endsWith('.html'))!; | ||
|
||
const regex = /integrity=/g; | ||
|
||
const matches = files[htmlFileName].match(regex); | ||
|
||
// at least 1 js file and 1 css file | ||
expect(matches?.length).toBeGreaterThanOrEqual(2); | ||
|
||
await page.goto(getHrefByEntryName('index', builder.port)); | ||
|
||
await expect( | ||
page.evaluate(`document.getElementById('test').innerHTML`), | ||
).resolves.toBe('Hello Builder!'); | ||
|
||
builder.close(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
html, | ||
body { | ||
padding: 0; | ||
margin: 0; | ||
font-family: nunito_for_arco, Helvetica Neue, Helvetica, PingFang SC, | ||
Hiragino Sans GB, Microsoft YaHei, 微软雅黑, Arial, sans-serif; | ||
} | ||
|
||
* { | ||
-webkit-font-smoothing: antialiased; | ||
-moz-osx-font-smoothing: grayscale; | ||
box-sizing: border-box; | ||
} | ||
|
||
.description { | ||
text-align: center; | ||
line-height: 1.5; | ||
font-size: 16px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import './App.css'; | ||
|
||
const App = () => ( | ||
<div className="container"> | ||
<div id="test">Hello Builder!</div> | ||
</div> | ||
); | ||
|
||
export default App; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import React from 'react'; | ||
import { render } from 'react-dom'; | ||
import App from './App'; | ||
|
||
// eslint-disable-next-line no-undef | ||
render(React.createElement(App), document.getElementById('root')); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters