Skip to content

Commit b0e6520

Browse files
committed
test: some more tests
1 parent da9ec10 commit b0e6520

File tree

8 files changed

+425
-23
lines changed

8 files changed

+425
-23
lines changed

.github/workflows/release.yml

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,17 @@ jobs:
1616
node_version: 12
1717
- name: Install
1818
run: yarn install --frozen-lockfile
19-
# - name: Prepare Npm
20-
# run: sh npm.sh
21-
# env:
22-
# REGISTRY_AUTH_TOKEN: ${{ secrets.REGISTRY_AUTH_TOKEN }}
23-
# REGISTRY_URL: registry.npmjs.org
19+
- name: Prepare Npm
20+
run: sh npm.sh
21+
env:
22+
REGISTRY_AUTH_TOKEN: ${{ secrets.REGISTRY_AUTH_TOKEN }}
23+
REGISTRY_URL: registry.npmjs.org
24+
- name: Test
25+
run: npm run test
26+
env:
27+
REGISTRY_AUTH_TOKEN: ${{ secrets.REGISTRY_AUTH_TOKEN }}
28+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Github already has this token by default in repo
29+
REGISTRY_URL: registry.npmjs.org
2430
# - name: Run
2531
# run: npm run build
2632
# env:

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
cssnano
22
node_modules
3-
.npmrc
3+
.npmrc
4+
test/fixture/output.css
5+
test/fixture/package-lock.json

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
},
1515
"devDependencies": {
1616
"jest": "^26.1.0",
17+
"postcss-cli": "^7.1.1",
1718
"tmp": "^0.2.1",
1819
"verdaccio": "^4.6.2",
1920
"verdaccio-auth-memory": "^9.5.0",

test/fixture/input.css

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/* normalize selectors */
2+
h1::before,
3+
h1:before {
4+
/* reduce shorthand even further */
5+
margin: 10px 20px 10px 20px;
6+
/* reduce color values */
7+
color: #ff0000;
8+
/* remove duplicated properties */
9+
font-weight: 400;
10+
font-weight: 400;
11+
/* reduce position values */
12+
background-position: bottom right;
13+
/* normalize wrapping quotes */
14+
quotes: "«" "»";
15+
/* reduce gradient parameters */
16+
background: linear-gradient(
17+
to bottom,
18+
#ffe500 0%,
19+
#ffe500 50%,
20+
#121 50%,
21+
#121 100%
22+
);
23+
/* replace initial values */
24+
min-width: initial;
25+
}
26+
/* correct invalid placement */
27+
@charset "utf-8";

test/fixture/package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"dependencies": {
3+
"cssnano": "^4.0.0-nightly.0.7.8"
4+
}
5+
}

test/fixture/postcss.config.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module.exports = {
2+
plugins: [
3+
require("cssnano")({
4+
preset: "default"
5+
})
6+
]
7+
};

test/index.test.js

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
const path = require("path");
2+
const fs = require("fs");
23
const shell = require("shelljs");
34
const { spawnRegistry } = require("./helper/registry");
4-
// const { runNmp } = require("./helper/npm");
5-
// const { runCli } = require("./helper/cli");
65
const rimraf = require("rimraf");
7-
const { getTempFolder } = require("./helper/fs-utils");
86
const tmp = require("tmp");
7+
const { runCli } = require("./helper/cli");
98
const { tag } = require("../versions");
109
const publish = require("../publish");
1110

@@ -16,10 +15,8 @@ const registryUrl = "http://localhost:4873/";
1615

1716
describe("E2E cssnano ", () => {
1817
let childFork;
19-
const folder = getTempFolder();
20-
let tmpDir;
18+
2119
beforeAll(async () => {
22-
// tmpDir = tmp.dirSync();
2320
childFork = await spawnRegistry();
2421
try {
2522
await publish(registryUrl);
@@ -32,9 +29,7 @@ describe("E2E cssnano ", () => {
3229
if (childFork) {
3330
childFork.kill();
3431
}
35-
if (tmpDir) {
36-
tmpDir.removeCallback();
37-
}
32+
3833
rimraf.sync("cssnano");
3934
});
4035

@@ -45,4 +40,32 @@ describe("E2E cssnano ", () => {
4540
).toBe(0);
4641
done();
4742
});
43+
44+
it(
45+
"should minify the input using postcss cli and cssnano" + tag,
46+
async done => {
47+
await shell.cd(__dirname + "/fixture");
48+
await shell.exec(
49+
"npm install cssnano@" + tag + " --registry " + registryUrl
50+
);
51+
52+
const cmdOutput = await runCli(
53+
path.resolve(__dirname, "../node_modules", ".bin", "postcss"),
54+
[
55+
path.resolve(__dirname, "./fixture/input.css"),
56+
"-o",
57+
path.resolve(__dirname, "./fixture/output.css")
58+
]
59+
);
60+
expect(
61+
fs.existsSync(path.resolve(__dirname, "./fixture/output.css"))
62+
).toBe(true);
63+
const outputCode = fs.readFileSync(
64+
path.resolve(__dirname, "./fixture/output.css"),
65+
"utf-8"
66+
);
67+
expect(outputCode.split("\n").length).toBe(1);
68+
done();
69+
}
70+
);
4871
});

0 commit comments

Comments
 (0)