Skip to content

Commit

Permalink
Increases test coverage for prev sourcemaps & error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
webketje committed Dec 27, 2022
1 parent 7068ba1 commit 66c72c4
Show file tree
Hide file tree
Showing 7 changed files with 172 additions and 30 deletions.
126 changes: 97 additions & 29 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,10 @@
"build": "microbundle --target node --no-sourcemap -f cjs,esm --strict --generateTypes=false"
},
"devDependencies": {
"assert-dir-equal": "^1.0.1",
"@metalsmith/sass": "^1.2.0",
"assert-dir-equal": "github:webketje/assert-dir-equal#v2.0.0",
"auto-changelog": "^2.4.0",
"autoprefixer": "^10.4.13",
"eslint": "^8.30.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-import": "^2.26.0",
Expand Down
6 changes: 6 additions & 0 deletions test/fixtures/prev-sourcemaps/expected/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<head>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<p>I am peachpuff!</p>
</body>
2 changes: 2 additions & 0 deletions test/fixtures/prev-sourcemaps/expected/styles.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions test/fixtures/prev-sourcemaps/src/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<head>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<p>I am peachpuff!</p>
</body>
18 changes: 18 additions & 0 deletions test/fixtures/prev-sourcemaps/src/styles.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
@mixin userSelectNone {
user-select: none;
}

body {
color: peachpuff;

p {
box-shadow: 0 0 5px black;
}

.example {
display: grid;
transition: all .5s;
@include userSelectNone();
background: linear-gradient(to bottom, white, black);
}
}
40 changes: 40 additions & 0 deletions test/index.cjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-env node, mocha */

const sass = require("@metalsmith/sass");
const path = require("path");
const assert = require("assert");
const fixture = path.resolve.bind(path, __dirname, "fixtures");
Expand Down Expand Up @@ -54,6 +55,25 @@ describe("@metalsmith/postcss", function () {
});
});

it("should handle errors appropriately", function (done) {
const ms = Metalsmith(fixture("no-sourcemaps"))
const files = {
'first.css': {
contents: Buffer.from('invalid-css')
}
}
postcss({
plugins: ['autoprefixer']
})(files, ms, (err) => {
if (err) {
assert.strictEqual(err.name, 'CssSyntaxError')
done()
} else {
done(new Error('should throw'))
}
})
});

describe("sourcemaps", function () {
it("should not add sourcemaps at all", function (done) {
const metalsmith = Metalsmith(fixture("no-sourcemaps"));
Expand Down Expand Up @@ -159,6 +179,26 @@ describe("@metalsmith/postcss", function () {
});
})

it('should take into account previous source maps', function(done) {
const ms = Metalsmith(fixture("prev-sourcemaps"))

ms
.use(sass({ sourceMap: true }))
.use(postcss({ map: { inline: true }, plugins: ['autoprefixer']}))
.build((err) => {
if (err) done(err)
try {
equal(
fixture("prev-sourcemaps/build"),
fixture("prev-sourcemaps/expected")
);
done()
} catch (err) {
done(err)
}
});
})

it("should pass absolute paths to postcss", function (done) {
const metalsmith = Metalsmith(fixture("use-absolute-paths"));
metalsmith
Expand Down

0 comments on commit 66c72c4

Please sign in to comment.