-
Notifications
You must be signed in to change notification settings - Fork 1k
Expand file tree
/
Copy pathtest.js
More file actions
111 lines (103 loc) · 2.86 KB
/
test.js
File metadata and controls
111 lines (103 loc) · 2.86 KB
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/* eslint-env jest */
// Include at the top of your tests. Automatically mocks out the file system
//
// import { loadComponentFixture } from 'src/lib/test'
//
// test('true is true', () => {
// expect('some output').toEqual(loadComponentFixture('component', 'filename.js'))
// })
import fs from 'fs'
import path from 'path'
jest.mock('@redwoodjs/internal', () => {
const path = require('path')
return {
...jest.requireActual('@redwoodjs/internal'),
generate: () => {},
getPaths: () => {
const BASE_PATH = '/path/to/project'
return {
base: BASE_PATH,
api: {
dataMigrations: path.join(BASE_PATH, './api/prisma/dataMigrations'),
db: path.join(global.__dirname, 'fixtures'), // this folder
src: path.join(BASE_PATH, './api/src'),
services: path.join(BASE_PATH, './api/src/services'),
graphql: path.join(BASE_PATH, './api/src/graphql'),
functions: path.join(BASE_PATH, './api/src/functions'),
},
web: {
src: path.join(BASE_PATH, './web/src'),
routes: path.join(BASE_PATH, 'web/src/Routes.js'),
components: path.join(BASE_PATH, '/web/src/components'),
layouts: path.join(BASE_PATH, '/web/src/layouts'),
pages: path.join(BASE_PATH, '/web/src/pages'),
},
scripts: path.join(BASE_PATH, 'scripts'),
generated: {
base: path.join(BASE_PATH, '.redwood'),
schema: path.join(BASE_PATH, '.redwood/schema.graphql'),
types: {
includes: path.join(BASE_PATH, '.redwood/types/includes'),
mirror: path.join(BASE_PATH, '.redwood/types/mirror'),
},
},
}
},
}
})
global.__prettierPath = path.resolve(
__dirname,
'./__tests__/fixtures/prettier.config.js'
)
jest.mock('path', () => {
const path = jest.requireActual('path')
return {
...path,
join: (...paths) => {
if (
paths &&
paths[0] === '/path/to/project' &&
paths[1] === 'prettier.config.js'
) {
return global.__prettierPath
}
return path.join(...paths)
},
}
})
export const generatorsRootPath = path.join(
__dirname,
'..',
'commands',
'generate'
)
/**
* Loads the fixture for a generator by assuming a lot of the path structure
* automatically:
*
* `loadGeneratorFixture('scaffold', 'NamePage.js')`
*
* will return the contents of:
*
* `cli/src/commands/generate/scaffold/__tests__/fixtures/NamePage.js`
*/
export const loadGeneratorFixture = (generator, name) => {
return loadFixture(
path.join(
__dirname,
'..',
'commands',
'generate',
generator,
'__tests__',
'fixtures',
name
)
)
}
/**
* Returns the contents of a text file in a `fixtures` directory
*/
export const loadFixture = (filepath) => {
return fs.readFileSync(filepath).toString()
}