Skip to content

Commit 3b3e8f7

Browse files
committed
feat: Initialize tests for broccoli plugin.
1 parent 660ffe1 commit 3b3e8f7

File tree

4 files changed

+83
-22
lines changed

4 files changed

+83
-22
lines changed

packages/broccoli-css-blocks/package.json

+16-13
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,29 @@
55
"main": "dist/src/index.js",
66
"author": "Adam Miller <[email protected]>",
77
"license": "MIT",
8-
"keywords": [
9-
"css-blocks",
10-
"css blocks",
11-
"broccoli-plugin"
12-
],
8+
"keywords": ["css-blocks", "css blocks", "broccoli-plugin"],
139
"scripts": {
14-
"test": "mocha --opts test/mocha.opts dist/test",
15-
"compile": "rm -rf dist && tsc -p tsconfig.json",
10+
"test": "../../node_modules/.bin/mocha --opts test/mocha.opts dist/test",
11+
"compile": "rm -rf dist && ../../node_modules/.bin/tsc -p tsconfig.json",
1612
"pretest": "yarn run compile",
1713
"posttest": "yarn run lint",
1814
"prepublish": "yarn run compile && yarn run lintall",
19-
"lint": "tslint -t msbuild --project . -c tslint.cli.json",
20-
"lintall": "tslint -t msbuild --project . -c tslint.release.json",
21-
"lintfix": "tslint -t msbuild --project . -c tslint.cli.json --fix",
22-
"coverage": "istanbul cover -i dist/src/**/*.js --dir ./build/coverage node_modules/mocha/bin/_mocha -- dist/test --opts test/mocha.opts",
23-
"remap": "remap-istanbul -i build/coverage/coverage.json -o coverage -t html",
15+
"lint":
16+
"../../node_modules/.bin/tslint -t msbuild --project . -c tslint.cli.json",
17+
"lintall":
18+
"../../node_modules/.bin/tslint -t msbuild --project . -c tslint.release.json",
19+
"lintfix":
20+
"../../node_modules/.bin/tslint -t msbuild --project . -c tslint.cli.json --fix",
21+
"coverage":
22+
"istanbul cover -i dist/src/**/*.js --dir ./build/coverage node_modules/mocha/bin/_mocha -- dist/test --opts test/mocha.opts",
23+
"remap":
24+
"remap-istanbul -i build/coverage/coverage.json -o coverage -t html",
2425
"docs": "typedoc --out ./docs .",
2526
"watch": "watch 'yarn run test' src test types-local --wait=1"
2627
},
2728
"devDependencies": {
28-
"@css-blocks/code-style": "^0.17.0"
29+
"@css-blocks/code-style": "^0.17.0",
30+
"@css-blocks/glimmer-templates": "^0.17.0"
2931
},
3032
"dependencies": {
3133
"@glimmer/compiler": "^0.33.0",
@@ -34,6 +36,7 @@
3436
"broccoli-funnel": "^2.0.1",
3537
"broccoli-merge-trees": "^3.0.0",
3638
"broccoli-plugin": "^1.3.0",
39+
"broccoli-test-helper": "^1.2.0",
3740
"colors": "^1.2.1",
3841
"css-blocks": "^0.17.0",
3942
"debug": "^3.1.0",

packages/broccoli-css-blocks/src/index.ts

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,26 @@
11
import * as fs from "fs-extra";
22
import * as path from "path";
33

4-
import { TemplateTypes } from "@opticss/template-api";
4+
// import { TemplateTypes } from "@opticss/template-api";
55
import { Analyzer, BlockCompiler, StyleMapping } from "css-blocks";
66
import { Optimizer } from "opticss";
77
import * as postcss from "postcss";
88
import * as readdir from "recursive-readdir";
99

1010
import { BroccoliPlugin } from "./utils";
1111

12-
interface BroccoliOptions {
12+
export interface BroccoliOptions {
1313
entry: string[];
1414
output: string;
15-
analyzer: Analyzer<keyof TemplateTypes>;
15+
// tslint:disable-next-line:prefer-whatever-to-any
16+
analyzer: Analyzer<any>;
1617
transport: {[key: string]: object};
1718
}
1819

1920
class BroccoliCSSBlocks extends BroccoliPlugin {
2021

21-
private analyzer: Analyzer<keyof TemplateTypes>;
22+
// tslint:disable-next-line:prefer-whatever-to-any
23+
private analyzer: Analyzer<any>;
2224
private entry: string[];
2325
private output: string;
2426
private transport: { [key: string]: object };
@@ -111,4 +113,4 @@ class BroccoliCSSBlocks extends BroccoliPlugin {
111113

112114
}
113115

114-
module.exports = BroccoliCSSBlocks;
116+
export { BroccoliCSSBlocks };
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,63 @@
1+
import { GlimmerAnalyzer } from "@css-blocks/glimmer-templates";
12
import * as assert from "assert";
3+
import { buildOutput, createTempDir, TempDir } from "broccoli-test-helper";
24

3-
describe("Broccoli Plugin Test", () => {
4-
it("runs tests", () => {
5-
assert.ok(1);
5+
import { BroccoliCSSBlocks } from "../src/index";
6+
7+
describe("Broccoli Plugin Test", function() {
8+
let input: TempDir;
9+
10+
beforeEach(async () => {
11+
input = await createTempDir();
12+
});
13+
14+
afterEach(async () => {
15+
await input.dispose();
16+
});
17+
18+
describe("Broccoli Plugin Test", () => {
19+
it("runs tests", () => {
20+
assert.ok(1);
21+
});
22+
23+
it("outputs CSS file", async () => {
24+
const entryComponentName = "Chrisrng";
25+
26+
input.write({
27+
"package.json": `{
28+
"name": "chrisrng-test"
29+
}`,
30+
src: {
31+
ui: {
32+
components: {
33+
[entryComponentName]: {
34+
"template.hbs": `<div><h1 class="foo">Welcome to Glimmer!</h1></div>`,
35+
"stylesheet.block.css": `:scope {
36+
color: red;
37+
}
38+
39+
.foo {
40+
color: green;
41+
}`,
42+
},
43+
},
44+
},
45+
},
46+
});
47+
48+
let analyzer = new GlimmerAnalyzer(input.path());
49+
50+
let compiler = new BroccoliCSSBlocks(input.path(), {
51+
entry: [entryComponentName],
52+
output: "src/ui/styles/css-blocks.css",
53+
transport: {},
54+
analyzer,
55+
});
56+
57+
let output = await buildOutput(compiler);
58+
let files = output.read();
59+
60+
assert.ok(files["src"]!["ui"]["styles"]["css-blocks.css"]);
61+
});
662
});
763
});
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"extends": "@css-blocks/code-style"
2+
"extends": "@css-blocks/code-style/configs/tslint.cli.json"
33
}

0 commit comments

Comments
 (0)