-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[zero] Setup basic testing framework
- Loading branch information
1 parent
4a884da
commit abde207
Showing
8 changed files
with
94 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Adding new fixtures | ||
|
||
Create a new file name with `[name].input.js` and add `styled`, `css` or other zero-runtime calls into the file. Also add equivalent `[name].output.js` and `[name].output.css` and run the test. After the new test fails, get the results from the received output and add it to the equivalent js and css files. This is equivalent to snapshot testing and will make sure any change in internal css generation logic does not fail any other existing tests. |
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,5 @@ | ||
import { styled } from '@mui/zero-runtime'; | ||
|
||
const Component = styled.div(({ theme }) => ({ | ||
color: theme.palette.primary.main, | ||
})); |
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 @@ | ||
.c1yjyf7p{color:red;} |
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,5 @@ | ||
import { styled as _styled } from "@mui/zero-runtime"; | ||
import _theme from "@mui/zero-runtime/theme"; | ||
const Component = /*#__PURE__*/_styled("div")({ | ||
classes: ["c1yjyf7p"] | ||
}); |
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,64 @@ | ||
import * as fs from 'node:fs'; | ||
import * as path from 'node:path'; | ||
import { expect } from 'chai'; | ||
import { asyncResolveFallback } from '@wyw-in-js/shared'; | ||
import { TransformCacheCollection, transform, createFileReporter } from '@wyw-in-js/transform'; | ||
|
||
const files = fs.readdirSync(path.join(__dirname, 'fixtures')); | ||
|
||
const theme = { | ||
palette: { | ||
primary: { | ||
main: 'red', | ||
}, | ||
}, | ||
}; | ||
|
||
describe('zero-runtime', () => { | ||
files.forEach((file) => { | ||
it(`test input file ${file}`, async () => { | ||
if (file.includes('.output.')) { | ||
return; | ||
} | ||
const cache = new TransformCacheCollection(); | ||
const { emitter: eventEmitter } = createFileReporter(false); | ||
const inputFilePath = path.join(__dirname, 'fixtures', file); | ||
const outputFilePath = path.join(__dirname, 'fixtures', file.replace('.input.', '.output.')); | ||
const outputCssFilePath = path.join( | ||
__dirname, | ||
'fixtures', | ||
file.replace('.input.js', '.output.css'), | ||
); | ||
const inputContent = fs.readFileSync(inputFilePath, 'utf8'); | ||
const outputContent = fs.readFileSync(outputFilePath, 'utf8'); | ||
const outputCssContent = fs.readFileSync(outputCssFilePath, 'utf8'); | ||
|
||
const result = await transform( | ||
{ | ||
options: { | ||
filename: inputFilePath, | ||
pluginOptions: { | ||
themeArgs: { | ||
theme, | ||
}, | ||
babelOptions: { | ||
configFile: false, | ||
babelrc: false, | ||
}, | ||
tagResolver(_source, tag) { | ||
return require.resolve(`../exports/${tag}`); | ||
}, | ||
}, | ||
}, | ||
cache, | ||
eventEmitter, | ||
}, | ||
inputContent, | ||
asyncResolveFallback, | ||
); | ||
|
||
expect(result.code.trim()).to.equal(outputContent.trim()); | ||
expect(result.cssText).to.equal(outputCssContent); | ||
}); | ||
}); | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.