forked from mui/material-ui
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[pigment] Improve testing of fixtures (mui#41389)
Co-authored-by: siriwatknp <siriwatkunaporn@gmail.com>
- Loading branch information
Showing
21 changed files
with
306 additions
and
115 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 |
---|---|---|
@@ -1,3 +1,35 @@ | ||
# Adding new fixtures | ||
# Pigment CSS testing | ||
|
||
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. | ||
## Folder structure | ||
|
||
- `tests` is the root folder for all tests | ||
- `fixtures` contains all the fixtures for the tests | ||
- `*.input.js` are the input files created manually | ||
- `*.output.*` are the expected output files created by running the tests | ||
- `*.test.js` are the test files that run the fixtures | ||
|
||
## Running tests | ||
|
||
At the root project terminal: | ||
|
||
```bash | ||
pnpm nx run @pigment-css/react:test | ||
``` | ||
|
||
To update the output fixtures: | ||
|
||
```bash | ||
pnpm nx run @pigment-css/react:test:update | ||
``` | ||
|
||
## Adding new tests | ||
|
||
Each folder inside `tests` is a Pigment CSS feature. To add a new test, create a new folder with the feature name and add a new test file with the `.test.js` extension. Inside the test file, import the fixtures and run the tests. | ||
|
||
## Adding new fixtures | ||
|
||
Create a new file name with `[name].input.js` and add `styled`, `css` or other Pigment CSS calls into the file. | ||
|
||
The first time you run the tests, the output files will be created automatically. Then check the output files to make sure they are correct. | ||
|
||
For any implementation changes after that, if you want to update the output files, run the tests with the `test:update` script. |
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,40 @@ | ||
import path from 'node:path'; | ||
import { runTransformation, expect } from '../testUtils'; | ||
|
||
const theme = { | ||
palette: { | ||
primary: { | ||
main: 'red', | ||
}, | ||
}, | ||
size: { | ||
font: { | ||
h1: '3rem', | ||
}, | ||
}, | ||
components: { | ||
MuiSlider: { | ||
styleOverrides: { | ||
rail: { | ||
fontSize: '3rem', | ||
}, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
describe('Pigment CSS - css', () => { | ||
it('basics', async () => { | ||
const { output, fixture } = await runTransformation( | ||
path.join(__dirname, 'fixtures/css.input.js'), | ||
{ | ||
themeArgs: { | ||
theme, | ||
}, | ||
}, | ||
); | ||
|
||
expect(output.js).to.equal(fixture.js); | ||
expect(output.css).to.equal(fixture.css); | ||
}); | ||
}); |
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 { css } from '@pigment-css/react'; | ||
|
||
const cls1 = css` | ||
color: ${({ theme }) => theme.palette.primary.main}; | ||
font-size: ${({ theme }) => theme.size.font.h1}; | ||
`; |
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 @@ | ||
.c1wr0t7p { | ||
color: red; | ||
font-size: 3rem; | ||
} |
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 @@ | ||
const cls1 = 'c1wr0t7p'; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
10 changes: 10 additions & 0 deletions
10
packages/pigment-react/tests/keyframes/fixtures/keyframes.input.js
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,10 @@ | ||
import { keyframes } from '@pigment-css/react'; | ||
|
||
const rotateKeyframe = keyframes({ | ||
from: { | ||
transform: 'rotate(360deg)', | ||
}, | ||
to: { | ||
transform: 'rotate(0deg)', | ||
}, | ||
}); |
8 changes: 8 additions & 0 deletions
8
packages/pigment-react/tests/keyframes/fixtures/keyframes.output.css
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,8 @@ | ||
@keyframes r14c1bqo { | ||
from { | ||
transform: rotate(360deg); | ||
} | ||
to { | ||
transform: rotate(0deg); | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
packages/pigment-react/tests/keyframes/fixtures/keyframes.output.js
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 @@ | ||
const rotateKeyframe = 'r14c1bqo'; |
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,13 @@ | ||
import path from 'node:path'; | ||
import { runTransformation, expect } from '../testUtils'; | ||
|
||
describe('Pigment CSS - keyframes', () => { | ||
it('basics', async () => { | ||
const { output, fixture } = await runTransformation( | ||
path.join(__dirname, 'fixtures/keyframes.input.js'), | ||
); | ||
|
||
expect(output.js).to.equal(fixture.js); | ||
expect(output.css).to.equal(fixture.css); | ||
}); | ||
}); |
This file was deleted.
Oops, something went wrong.
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
28 changes: 28 additions & 0 deletions
28
packages/pigment-react/tests/styled/fixtures/styled.output.css
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,28 @@ | ||
@keyframes r1419f2q { | ||
from { | ||
transform: rotate(360deg); | ||
} | ||
to { | ||
transform: rotate(0deg); | ||
} | ||
} | ||
.c1vtarpi { | ||
color: red; | ||
animation: r1419f2q 2s ease-out 0s infinite; | ||
} | ||
.s1sjy0ja { | ||
display: none; | ||
position: absolute; | ||
border-radius: inherit; | ||
background-color: currentColor; | ||
opacity: 0.38; | ||
font-size: 3rem; | ||
} | ||
.s1sjy0ja-1 { | ||
font-size: 3rem; | ||
} | ||
.s6hrafw { | ||
display: block; | ||
opacity: 0.38; | ||
font-size: 3rem; | ||
} |
16 changes: 16 additions & 0 deletions
16
packages/pigment-react/tests/styled/fixtures/styled.output.js
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,16 @@ | ||
import { styled as _styled3 } from '@pigment-css/react'; | ||
import { styled as _styled2 } from '@pigment-css/react'; | ||
import { styled as _styled } from '@pigment-css/react'; | ||
import _theme from '@pigment-css/react/theme'; | ||
const Component = /*#__PURE__*/ _styled('div')({ | ||
classes: ['c1vtarpi'], | ||
}); | ||
const SliderRail = /*#__PURE__*/ _styled2('span', { | ||
name: 'MuiSlider', | ||
slot: 'Rail', | ||
})({ | ||
classes: ['s1sjy0ja', 's1sjy0ja-1'], | ||
}); | ||
const SliderRail2 = /*#__PURE__*/ _styled3('span')({ | ||
classes: ['s6hrafw'], | ||
}); |
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,40 @@ | ||
import path from 'node:path'; | ||
import { runTransformation, expect } from '../testUtils'; | ||
|
||
const theme = { | ||
palette: { | ||
primary: { | ||
main: 'red', | ||
}, | ||
}, | ||
size: { | ||
font: { | ||
h1: '3rem', | ||
}, | ||
}, | ||
components: { | ||
MuiSlider: { | ||
styleOverrides: { | ||
rail: { | ||
fontSize: '3rem', | ||
}, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
describe('Pigment CSS - styled', () => { | ||
it('basics', async () => { | ||
const { output, fixture } = await runTransformation( | ||
path.join(__dirname, 'fixtures/styled.input.js'), | ||
{ | ||
themeArgs: { | ||
theme, | ||
}, | ||
}, | ||
); | ||
|
||
expect(output.js).to.equal(fixture.js); | ||
expect(output.css).to.equal(fixture.css); | ||
}); | ||
}); |
Oops, something went wrong.