1
1
mirror of https://github.com/primer/css.git synced 2024-12-23 06:01:54 +03:00
css/modules/generator-primer-module/test/generator.spec.js

103 lines
2.9 KiB
JavaScript
Raw Normal View History

2017-09-01 21:58:44 +03:00
const test = require("ava")
const assert = require("yeoman-assert")
const generate = require("./lib/generate")
2017-09-07 01:33:18 +03:00
// XXX: this is required to work around the low EventEmitter default of 10 max
// listeners, above which it starts to complain that there's a memory leak
// <https://github.com/npm/npm/issues/13806#issuecomment-257843863>
require('events').EventEmitter.defaultMaxListeners = 100;
2017-09-01 21:58:44 +03:00
test("file scaffolding", t => {
const module = "primer-test"
2017-09-07 01:33:18 +03:00
return generate({prompts: {module}})
2017-09-01 21:58:44 +03:00
.then(path => {
2017-09-07 01:33:18 +03:00
const pkg = path("package.json")
2017-09-01 21:58:44 +03:00
assert.file(pkg)
assert.jsonFileContent(pkg, {name: module},
"Wrong module name in package.json")
2017-09-05 20:44:16 +03:00
assert.jsonFileContent(pkg, {version: "0.0.1"},
2017-09-01 21:58:44 +03:00
"Wrong or empty version in package.json")
2017-09-07 01:33:18 +03:00
const readme = path("README.md")
2017-09-01 21:58:44 +03:00
assert.file(readme)
2017-09-07 01:33:18 +03:00
assert.fileContent(readme, /# Primer CSS \/ Test/)
2017-09-01 21:58:44 +03:00
assert.fileContent(readme, `npmjs.org/package/${module}`)
assert.fileContent(readme, `npm install --save ${module}`)
2017-09-07 01:33:18 +03:00
assert.file(path("lib/test.scss"))
t.pass("All the files exist.")
})
})
test("default title", t => {
const titles = {
"primer-test": "Test",
"primer-foo-bar": "Foo Bar",
}
t.plan(Object.keys(titles).length)
return Promise.all(
Object.keys(titles).map(module => {
const title = titles[module]
return generate({prompts: {module}})
.then(path => {
const readme = path("README.md")
assert.fileContent(readme, `\ntitle: ${title}\n`)
t.pass("module: '%s' => title: '%s'", module, title)
})
})
)
})
test("missing description gets a TODO", t => {
return generate().then(path => {
assert.jsonFileContent(path("package.json"), {description: /TODO/})
t.pass("TODO in the package.json description")
})
})
test("primer.category is set", t => {
const values = ["core", "product", "marketing", "meta", ""]
t.plan(values.length)
return Promise.all(
values.map(category => {
return generate({prompts: {category}})
.then(path => {
assert.jsonFileContent(path("package.json"), {
primer: {category}
})
t.pass(category)
})
})
)
})
2017-09-01 21:58:44 +03:00
2017-09-07 01:33:18 +03:00
test("primer.module_type is set", t => {
const values = [
"components",
"objects",
"utilities",
"meta",
"",
]
t.plan(values.length)
return Promise.all(
values.map(module_type => {
return generate({prompts: {module_type}})
.then(path => {
assert.jsonFileContent(path("package.json"), {
primer: {module_type}
})
t.pass(module_type)
})
2017-09-01 21:58:44 +03:00
})
2017-09-07 01:33:18 +03:00
)
})
test("status: Experimental is written to %docs comment", t => {
return generate().then(path => {
assert.fileContent(path("README.md"), "\nstatus: Experimental\n")
t.pass("status: Experimental")
})
2017-09-01 21:58:44 +03:00
})