Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: use snapshot and split into multiple files #143

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.DS_Store
.idea/
.vscode/
.nyc_output/
.tests-output/

Expand Down
2,439 changes: 1,125 additions & 1,314 deletions package-lock.json

Large diffs are not rendered by default.

17 changes: 11 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"build": "npm run build-downlevel-dts && tsc --project tsconfig.build.plugin.json && tsc --project tsconfig.build.insertStyle.json",
"build-downlevel-dts": "node scripts/clean-and-run-downlevel-dts.js",
"downlevel-dts": "downlevel-dts . ts3.5 [--to=3.5]",
"test": "nyc --reporter=html --reporter=text ava ./test/*.test.ts -s && npm run test:rollup.config.spec.ts",
"test": "nyc --reporter=html --reporter=text ava && npm run test:rollup.config.spec.ts",
"coverage": "nyc report --reporter=text-lcov | coveralls",
"output-coverage-lcov": "nyc report --reporter=text-lcov > coverage/tests.lcov",
"test:rollup.config.spec.ts": "tsc --project tsconfig.spec.json --noEmit",
Expand Down Expand Up @@ -50,6 +50,9 @@
"dist"
],
"ava": {
"files": [
"./test/*.test.ts"
],
"extensions": [
"ts"
],
Expand All @@ -64,22 +67,24 @@
"sass": "^1.7.2"
},
"devDependencies": {
"@ava/typescript": "^3.0.1",
"@ava/typescript": "^5.0.0",
"@commitlint/cli": "^19.3.0",
"@commitlint/config-conventional": "^19.2.2",
"@types/icss-utils": "^5.1.2",
"@types/node": "^18.14.6",
"@types/resolve": "^0.0.8",
"ava": "^4.3.1",
"@types/sinon": "^17.0.3",
"ava": "^6.1.3",
"coveralls-next": "^4.2.1",
"downlevel-dts": "^0.10.0",
"eslint": "^7.32.0",
"happy-dom": "^14.12.3",
"husky": "^9.0.11",
"icss-utils": "^5.1.0",
"jsdom": "^17.0.0",
"nyc": "^15.1.0",
"nyc": "^17.0.0",
"postcss": "^8.4.16",
"rollup": "^1 || ^2 || ^3",
"sinon": "^7.2.2",
"sinon": "^18.0.0",
"ts-node": "^10.9.1",
"typescript": "^4.7.4"
},
Expand Down
76 changes: 76 additions & 0 deletions test/basic.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import test from "ava";
import { rollup } from "rollup";
import * as path from "path";

import sass from "../src/index";
import {
TEST_UTILS,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So for TEST_UTILS, could you change the exports to just the methods themselves - Since they already live at 'test/utils' it becomes redundant to export the object TEST_UTILS - What would be good here would be to rename squash to stripNewLines, or something similar!

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, getOutputFirstChunkCode could just be getFirstChunkCode - since the declaration would read getFirstChunkCode(output: ...) ... - Would also change output to chunks, and/or, outputChunks for more correlation between what output constants actually represent.

TEST_BASE_CONFIG,
TEST_SASS_OPTIONS_DEFAULT,
TEST_GENERATE_OPTIONS,
TEST_OUTPUT_DIR,
} from "./utils";

test("should import *.scss and *.sass files", async (t) => {
const outputBundle = await rollup({
input: "test/fixtures/basic/index.js",
...TEST_BASE_CONFIG,
});
const { output } = await outputBundle.generate({
format: "es",
file: path.join(TEST_OUTPUT_DIR, "import_scss_and_sass.js"),
});
const result = TEST_UTILS.getOutputFirstChunkCode(output);

t.snapshot(result);
});

test("should import *.scss and *.sass files with default configuration", async (t) => {
const outputBundle = await rollup({
input: "test/fixtures/basic/index.js",
plugins: [sass()],
});
const { output } = await outputBundle.generate({
...TEST_GENERATE_OPTIONS,
file: path.join(TEST_OUTPUT_DIR, "import_scss_and_sass_default_options.js"),
});
const result = TEST_UTILS.getOutputFirstChunkCode(output);

t.snapshot(result);
});

test("should compress the dest CSS", async (t) => {
const outputBundle = await rollup({
...TEST_BASE_CONFIG,
input: "test/fixtures/compress/index.js",
});
const { output } = await outputBundle.generate(TEST_GENERATE_OPTIONS);
const result = TEST_UTILS.getOutputFirstChunkCode(output);

t.snapshot(result);
});

test("should support options.data", async (t) => {
const jsVars = {
color_red: "red",
};
const scssVars = Object.entries(jsVars).reduce(
(prev, [varName, varValue]) => `${prev}$${varName}:${varValue};`,
""
);
const outputBundle = await rollup({
input: "test/fixtures/data/index.js",
plugins: [
sass({
options: {
...TEST_SASS_OPTIONS_DEFAULT,
data: scssVars,
},
}),
],
});
const { output } = await outputBundle.generate(TEST_GENERATE_OPTIONS);
const result = TEST_UTILS.getOutputFirstChunkCode(output);

t.snapshot(result);
});
Loading
Loading