Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
2d7995f5
Unverified
Commit
2d7995f5
authored
Aug 04, 2024
by
Sebastian Silbermann
Committed by
GitHub
Aug 04, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Colocate `cssnanon-preset-simple` unit test with source (#68508)
parent
e4211f6b
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
119 additions
and
121 deletions
+119
-121
cssnano-preset-simple.test.ts
.../src/bundles/cssnano-simple/cssnano-preset-simple.test.ts
+119
-0
issue-1.test.ts
...unit/cssnano-simple/cssnano-preset-simple/issue-1.test.ts
+0
-8
plugin-config.test.ts
...ssnano-simple/cssnano-preset-simple/plugin-config.test.ts
+0
-40
plugin.ts
test/unit/cssnano-simple/cssnano-preset-simple/plugin.ts
+0
-30
property-sorting.test.ts
...ano-simple/cssnano-preset-simple/property-sorting.test.ts
+0
-24
with-escaped-selector.ts
...ano-simple/cssnano-preset-simple/with-escaped-selector.ts
+0
-19
No files found.
packages/next/src/bundles/cssnano-simple/cssnano-preset-simple.test.ts
0 → 100644
View file @
2d7995f5
import
postcss
from
'postcss'
import
type
{
PluginCreator
}
from
'postcss'
// Since the cssnano-preset-simple.js will be bundled into cssnano-simple
// during pre-compilation, we need to test against the source file directly
// @ts-expect-error -- untyped file
import
cssnanoPresetSimple
from
'./cssnano-preset-simple'
const
cssnanoPlugin
:
PluginCreator
<
any
>
=
(
options
=
{})
=>
{
const
plugins
:
any
[]
=
[]
const
nanoPlugins
=
cssnanoPresetSimple
(
options
).
plugins
for
(
const
nanoPlugin
of
nanoPlugins
)
{
if
(
Array
.
isArray
(
nanoPlugin
))
{
let
[
processor
,
opts
]
=
nanoPlugin
if
(
typeof
opts
===
'undefined'
||
(
typeof
opts
===
'object'
&&
!
opts
.
exclude
)
||
(
typeof
opts
===
'boolean'
&&
opts
===
true
)
)
{
plugins
.
push
(
processor
(
opts
))
}
}
else
{
plugins
.
push
(
nanoPlugin
)
}
}
return
postcss
(
plugins
)
}
cssnanoPlugin
.
postcss
=
true
function
noopTemplate
(
strings
:
TemplateStringsArray
,
...
keys
:
string
[])
{
const
lastIndex
=
strings
.
length
-
1
return
(
strings
.
slice
(
0
,
lastIndex
).
reduce
((
p
,
s
,
i
)
=>
p
+
s
+
keys
[
i
],
''
)
+
strings
[
lastIndex
]
)
}
describe
(
'https://github.com/Timer/cssnano-preset-simple/issues/1'
,
()
=>
{
test
(
'evaluates without error'
,
()
=>
{
cssnanoPresetSimple
()
})
})
describe
(
'cssnano accepts plugin configuration'
,
()
=>
{
test
(
'should not remove all comments'
,
async
()
=>
{
const
input
=
noopTemplate
`
p {
/*! heading */
color: yellow;
}
`
const
res
=
await
postcss
([
cssnanoPlugin
({
discardComments
:
{}
})]).
process
(
input
,
{
from
:
'input.css'
,
to
:
'output.css'
,
}
)
expect
(
res
.
css
).
not
.
toBe
(
'p{color:#ff0}'
)
})
test
(
'should remove all comments'
,
async
()
=>
{
const
input
=
noopTemplate
`
p {
/*! heading */
color: yellow;
}
`
const
res
=
await
postcss
([
cssnanoPlugin
({
discardComments
:
{
removeAll
:
true
}
}),
]).
process
(
input
,
{
from
:
'input.css'
,
to
:
'output.css'
,
})
expect
(
res
.
css
).
toBe
(
'p{color:#ff0}'
)
})
})
describe
(
'property sorting'
,
()
=>
{
test
(
'should result in correct border width'
,
async
()
=>
{
const
input
=
noopTemplate
`
p {
border: 1px solid var(--test);
border-radius: var(--test);
border-width: 0;
}
`
const
res
=
await
postcss
([
cssnanoPlugin
]).
process
(
input
,
{
from
:
'input.css'
,
to
:
'output.css'
,
})
expect
(
res
.
css
).
toMatchInlineSnapshot
(
`"p{border-width:1px;border-radius:var(--test);border:0 solid var(--test)}"`
)
})
})
describe
(
'with escaped selector'
,
()
=>
{
test
(
'should not misplace the backslash'
,
async
()
=>
{
const
input
=
`
.foo\\,2 {
background: blue;
}
`
const
res
=
await
postcss
([
cssnanoPlugin
]).
process
(
input
,
{
from
:
'input.css'
,
to
:
'output.css'
,
})
expect
(
res
.
css
).
toMatchInlineSnapshot
(
`".foo\\,2{background:blue}"`
)
})
})
test/unit/cssnano-simple/cssnano-preset-simple/issue-1.test.ts
deleted
100644 → 0
View file @
e4211f6b
import
cssnanoPresetSimple
from
'next/src/bundles/cssnano-simple/cssnano-preset-simple'
// https://github.com/Timer/cssnano-preset-simple/issues/1
describe
(
'https://github.com/Timer/cssnano-preset-simple/issues/1'
,
()
=>
{
test
(
'evaluates without error'
,
()
=>
{
cssnanoPresetSimple
()
})
})
test/unit/cssnano-simple/cssnano-preset-simple/plugin-config.test.ts
deleted
100644 → 0
View file @
e4211f6b
import
postcss
from
'postcss'
import
mod
from
'./plugin'
import
css
from
'../noop-template'
describe
(
'cssnano accepts plugin configuration'
,
()
=>
{
test
(
'should not remove all comments'
,
async
()
=>
{
const
input
=
css
`
p {
/*! heading */
color: yellow;
}
`
const
res
=
await
postcss
([
mod
({
discardComments
:
{}
})]).
process
(
input
,
{
from
:
'input.css'
,
to
:
'output.css'
,
})
expect
(
res
.
css
).
not
.
toBe
(
'p{color:#ff0}'
)
})
test
(
'should remove all comments'
,
async
()
=>
{
const
input
=
css
`
p {
/*! heading */
color: yellow;
}
`
const
res
=
await
postcss
([
mod
({
discardComments
:
{
removeAll
:
true
}
}),
]).
process
(
input
,
{
from
:
'input.css'
,
to
:
'output.css'
,
})
expect
(
res
.
css
).
toBe
(
'p{color:#ff0}'
)
})
})
test/unit/cssnano-simple/cssnano-preset-simple/plugin.ts
deleted
100644 → 0
View file @
e4211f6b
// https://github.com/Timer/cssnano-preset-simple/blob/master/test/plugin.js
import
postcss
from
'postcss'
import
type
{
PluginCreator
}
from
'postcss'
// Since the cssnano-preset-simple.js will be bundled into cssnano-simple
// during pre-compilation, we need to test against the source file directly
import
cssnanoPresetSimple
from
'next/src/bundles/cssnano-simple/cssnano-preset-simple'
const
cssnanoPlugin
=
(
options
=
{})
=>
{
const
plugins
:
any
[]
=
[]
const
nanoPlugins
=
cssnanoPresetSimple
(
options
).
plugins
for
(
const
nanoPlugin
of
nanoPlugins
)
{
if
(
Array
.
isArray
(
nanoPlugin
))
{
let
[
processor
,
opts
]
=
nanoPlugin
if
(
typeof
opts
===
'undefined'
||
(
typeof
opts
===
'object'
&&
!
opts
.
exclude
)
||
(
typeof
opts
===
'boolean'
&&
opts
===
true
)
)
{
plugins
.
push
(
processor
(
opts
))
}
}
else
{
plugins
.
push
(
nanoPlugin
)
}
}
return
postcss
(
plugins
)
}
cssnanoPlugin
.
postcss
=
true
export
default
cssnanoPlugin
as
PluginCreator
<
any
>
test/unit/cssnano-simple/cssnano-preset-simple/property-sorting.test.ts
deleted
100644 → 0
View file @
e4211f6b
import
postcss
from
'postcss'
import
mod
from
'./plugin'
import
css
from
'../noop-template'
describe
(
'property sorting'
,
()
=>
{
test
(
'should result in correct border width'
,
async
()
=>
{
const
input
=
css
`
p {
border: 1px solid var(--test);
border-radius: var(--test);
border-width: 0;
}
`
const
res
=
await
postcss
([
mod
]).
process
(
input
,
{
from
:
'input.css'
,
to
:
'output.css'
,
})
expect
(
res
.
css
).
toMatchInlineSnapshot
(
`"p{border-width:1px;border-radius:var(--test);border:0 solid var(--test)}"`
)
})
})
test/unit/cssnano-simple/cssnano-preset-simple/with-escaped-selector.ts
deleted
100644 → 0
View file @
e4211f6b
import
postcss
from
'postcss'
import
mod
from
'./plugin'
describe
(
'with escaped selector'
,
()
=>
{
test
(
'should not misplace the backslash'
,
async
()
=>
{
const
input
=
`
.foo\\,2 {
background: blue;
}
`
const
res
=
await
postcss
([
mod
]).
process
(
input
,
{
from
:
'input.css'
,
to
:
'output.css'
,
})
expect
(
res
.
css
).
toMatchInlineSnapshot
(
`".foo\\\\,2{background:blue}"`
)
})
})
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment