-
Notifications
You must be signed in to change notification settings - Fork 10.3k
/
new.js
89 lines (74 loc) · 2.68 KB
/
new.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import { GatsbyCLI } from "../test-helpers"
import * as fs from "fs-extra"
import execa from "execa"
import { join } from "path"
import { getConfigStore } from "gatsby-core-utils"
const MAX_TIMEOUT = 30000
jest.setTimeout(MAX_TIMEOUT)
const cwd = `execution-folder`
const clean = dir => execa(`yarn`, ["del-cli", dir])
describe(`gatsby new`, () => {
// make folder for us to create sites into
const dir = join(__dirname, "../execution-folder")
const originalPackageManager =
getConfigStore().get("cli.packageManager") || `npm`
beforeAll(async () => {
await clean(dir)
await fs.ensureDir(dir)
GatsbyCLI.from(cwd).invoke([`options`, `set`, `pm`, `yarn`])
})
afterAll(async () => {
GatsbyCLI.from(cwd).invoke([`options`, `set`, `pm`, originalPackageManager])
await clean(dir)
})
it(`creates a gatsby site with the default starter`, () => {
const [code, logs] = GatsbyCLI.from(cwd).invoke([
`new`,
`gatsby-default`,
`gatsbyjs/gatsby-starter-default#v3`,
])
logs.should.contain(
`info Creating new site from git: https://github.com/gatsbyjs/gatsby-starter-default.git`
)
logs.should.contain(`success Created starter directory layout`)
logs.should.contain(`info Installing packages...`)
logs.should.contain(
`Your new Gatsby site has been successfully bootstrapped. Start developing it by running:`
)
logs.should.contain(` cd gatsby-default`)
logs.should.contain(` gatsby develop`)
expect(code).toBe(0)
})
it(`creates a gatsby site with the blog starter`, () => {
const [code, logs] = GatsbyCLI.from(cwd).invoke([
`new`,
`gatsby-blog`,
`gatsbyjs/gatsby-starter-blog#v3`,
])
logs.should.contain(
`info Creating new site from git: https://github.com/gatsbyjs/gatsby-starter-blog.git`
)
logs.should.contain(`success Created starter directory layout`)
logs.should.contain(`info Installing packages...`)
logs.should.contain(
`Your new Gatsby site has been successfully bootstrapped. Start developing it by running:`
)
logs.should.contain(` cd gatsby-blog`)
logs.should.contain(` gatsby develop`)
expect(code).toBe(0)
})
it(`fails to create a gatsby site with an invalid starter`, () => {
const [code, logs] = GatsbyCLI.from(cwd).invoke([
`new`,
`gatsby-invalid`,
`tHiS-Is-A-fAkE-sTaRtEr`,
])
logs.should.contain(`Error`)
logs.should.contain(`starter tHiS-Is-A-fAkE-sTaRtEr doesn't exist`)
expect(code).toBe(1)
})
it(`runs create-gatsby when no arguments are provided to gatsby new`, () => {
const [_, logs] = GatsbyCLI.from(cwd).invoke([`new`])
logs.should.contain(`Welcome to Gatsby!`)
})
})