mirror of
https://github.com/primer/css.git
synced 2025-01-05 21:22:57 +03:00
clean up, add more tests
This commit is contained in:
parent
c65eeacd25
commit
828dd086c3
@ -67,26 +67,23 @@ module.exports = class PrimerModule extends Generator {
|
||||
"core",
|
||||
"product",
|
||||
"marketing",
|
||||
{
|
||||
value: "meta",
|
||||
message: "meta (this is a new meta-package)",
|
||||
},
|
||||
{
|
||||
value: undefined,
|
||||
message: "none (I'll figure this out later)",
|
||||
}
|
||||
"meta",
|
||||
""
|
||||
],
|
||||
default: "core"
|
||||
},
|
||||
{
|
||||
name: "module_type",
|
||||
message: "What type of module is this?",
|
||||
type: "option",
|
||||
type: "list",
|
||||
choices: [
|
||||
"utilities",
|
||||
"objects",
|
||||
"components",
|
||||
"objects",
|
||||
"utilities",
|
||||
"meta",
|
||||
"tools",
|
||||
],
|
||||
default: 0
|
||||
},
|
||||
{
|
||||
name: "dependents",
|
||||
@ -146,10 +143,12 @@ module.exports = class PrimerModule extends Generator {
|
||||
this.log("creating: %s", chalk.green(this.basePath))
|
||||
|
||||
const data = [
|
||||
"module",
|
||||
"category",
|
||||
"dependencies",
|
||||
"description",
|
||||
"docs",
|
||||
"module",
|
||||
"module_type",
|
||||
"status",
|
||||
"title",
|
||||
"type",
|
||||
|
@ -17,7 +17,6 @@ $ npm install --save <%= module %>
|
||||
|
||||
## Usage
|
||||
|
||||
<% if (type === "css") { %>
|
||||
The source files included are written in [Sass][sass] (SCSS) You can simply point your sass `include-path` at your `node_modules` directory and import it like this.
|
||||
|
||||
```scss
|
||||
@ -25,21 +24,14 @@ The source files included are written in [Sass][sass] (SCSS) You can simply poin
|
||||
```
|
||||
|
||||
You can also import specific portions of the module by importing those partials from the `/lib/` folder. _Make sure you import any requirements along with the modules._
|
||||
<% } else { %>
|
||||
<%= usage %>
|
||||
<% } %>
|
||||
|
||||
## Build
|
||||
|
||||
<% if (type === "css") { %>
|
||||
For a compiled **css** version of this module, a npm script is included that will output a css version to `build/build.css` The built css file is also included in the npm package.
|
||||
For a compiled **CSS** version of this module, an npm script is included that will output a css version to `build/build.css` The built css file is also included in the npm package:
|
||||
|
||||
```
|
||||
$ npm run build
|
||||
```
|
||||
<% } else { %>
|
||||
<%= build %>
|
||||
<% } %>
|
||||
|
||||
## Documentation
|
||||
|
||||
@ -48,7 +40,7 @@ title: <%= title %>
|
||||
status: <%= status || "Experimental" %>
|
||||
-->
|
||||
|
||||
<%= docs || "Documentation goes here." %>
|
||||
<%= docs || "TODO: Write some documentation here." %>
|
||||
|
||||
<!-- %enddocs -->
|
||||
|
||||
|
@ -3,6 +3,10 @@
|
||||
"name": "<%= module %>",
|
||||
"description": "<%= description %>",
|
||||
"homepage": "http://primercss.io/",
|
||||
"primer": {
|
||||
"category": "<%= category %>",
|
||||
"module_type": "<%= module_type %>"
|
||||
},
|
||||
"author": "GitHub, Inc.",
|
||||
"license": "MIT",
|
||||
"style": "index.scss",
|
||||
|
@ -2,30 +2,101 @@ const test = require("ava")
|
||||
const assert = require("yeoman-assert")
|
||||
const generate = require("./lib/generate")
|
||||
|
||||
// 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;
|
||||
|
||||
test("file scaffolding", t => {
|
||||
const module = "primer-test"
|
||||
return generate({
|
||||
prompts: {
|
||||
module,
|
||||
},
|
||||
})
|
||||
return generate({prompts: {module}})
|
||||
.then(path => {
|
||||
|
||||
const pkg = path(module, "package.json")
|
||||
const pkg = path("package.json")
|
||||
assert.file(pkg)
|
||||
assert.jsonFileContent(pkg, {name: module},
|
||||
"Wrong module name in package.json")
|
||||
assert.jsonFileContent(pkg, {version: "0.0.1"},
|
||||
"Wrong or empty version in package.json")
|
||||
|
||||
const readme = path(module, "README.md")
|
||||
const readme = path("README.md")
|
||||
assert.file(readme)
|
||||
assert.fileContent(readme, /# Primer .* Test/)
|
||||
assert.fileContent(readme, /# Primer CSS \/ Test/)
|
||||
assert.fileContent(readme, `npmjs.org/package/${module}`)
|
||||
assert.fileContent(readme, `npm install --save ${module}`)
|
||||
|
||||
assert.file(path(module, "lib/test.scss"))
|
||||
assert.file(path("lib/test.scss"))
|
||||
|
||||
t.pass("All the files exist!")
|
||||
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)
|
||||
})
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
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)
|
||||
})
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
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")
|
||||
})
|
||||
})
|
||||
|
@ -2,19 +2,23 @@ const yo = require('yeoman-test')
|
||||
const path = require('path')
|
||||
|
||||
const APP_PATH = path.join(__dirname, '../../app')
|
||||
// options, (positional) arguments, and prompts for all tests
|
||||
|
||||
// default options, (positional) arguments, and prompts for all tests
|
||||
const TEST_OPTS = {test: true}
|
||||
const TEST_ARGS = []
|
||||
const TEST_PROMPTS = {module: "primer-test"}
|
||||
|
||||
module.exports = (options) => {
|
||||
return yo.run(options.path || APP_PATH)
|
||||
.withOptions(Object.assign({}, TEST_OPTS, options.options))
|
||||
.withArguments((options.args || []).concat(TEST_ARGS))
|
||||
.withPrompts(Object.assign({}, TEST_PROMPTS, options.prompts))
|
||||
.inTmpDir(() => {})
|
||||
.then(dir => {
|
||||
module.exports = (config={}) => {
|
||||
const options = Object.assign({}, TEST_OPTS, config.options)
|
||||
const args = config.args || TEST_ARGS
|
||||
const prompts = Object.assign({}, TEST_PROMPTS, config.prompts)
|
||||
return yo.run(APP_PATH)
|
||||
.withOptions(options)
|
||||
.withArguments(args)
|
||||
.withPrompts(prompts)
|
||||
.inTmpDir()
|
||||
.then(tmpDir => {
|
||||
// return a path function that joins to the temp dir
|
||||
return (...args) => path.join(dir, ...args)
|
||||
return (...args) => path.join(tmpDir, prompts.module, ...args)
|
||||
})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user