-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
97 lines (79 loc) · 3.01 KB
/
test.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
90
91
92
93
94
95
96
97
import path from 'path';
import fs from 'fs';
import tempWrite from 'temp-write';
import dotProp from 'dot-prop';
import createWpThemeAuditor from '.';
const { get } = dotProp;
jest.setTimeout( 90000 );
async function run( pkg ) {
const filepath = tempWrite.sync( JSON.stringify( pkg ), 'package.json' );
await createWpThemeAuditor( {
cwd: path.dirname( filepath ),
skipInstall: true,
quiet: true,
} );
return JSON.parse( fs.readFileSync( filepath, 'utf8' ) );
}
test( 'Scripts added to empty package.json', async () => {
const pkg = await run( {} );
expect( get( pkg, 'scripts.create-test-cases' ) ).toBe( 'create-test-cases' );
expect( get( pkg, 'scripts.test:axe' ) ).toBe( 'wp-scripts test-e2e' );
expect( get( pkg, 'scripts.test' ) ).toBe( 'npm run -s test:axe' );
} );
test( 'Scripts added to package.json with existing scripts', async () => {
const pkg = await run( { scripts: {
lint: 'wp-scripts lint-js',
} } );
expect( get( pkg, 'scripts.create-test-cases' ) ).toBe( 'create-test-cases' );
expect( get( pkg, 'scripts.test:axe' ) ).toBe( 'wp-scripts test-e2e' );
expect( get( pkg, 'scripts.test' ) ).toBe( 'npm run -s test:axe' );
} );
test( 'Scripts added to package.json with default test', async () => {
const pkg = await run( {
scripts: {
test: 'echo "Error: no test specified" && exit 1',
},
} );
expect( get( pkg, 'scripts.create-test-cases' ) ).toBe( 'create-test-cases' );
expect( get( pkg, 'scripts.test:axe' ) ).toBe( 'wp-scripts test-e2e' );
expect( get( pkg, 'scripts.test' ) ).toBe( 'npm run -s test:axe' );
} );
test( 'Scripts added to package.json which already has test:axe', async () => {
const pkg = await run( {
scripts: {
test: 'npm run -s test:axe',
},
} );
expect( get( pkg, 'scripts.create-test-cases' ) ).toBe( 'create-test-cases' );
expect( get( pkg, 'scripts.test:axe' ) ).toBe( 'wp-scripts test-e2e' );
expect( get( pkg, 'scripts.test' ) ).toBe( 'npm run -s test:axe' );
} );
test( 'Scripts added to package.json which already has other tests', async () => {
const pkg = await run( {
scripts: {
test: 'npm run -s lint',
},
} );
expect( get( pkg, 'scripts.create-test-cases' ) ).toBe( 'create-test-cases' );
expect( get( pkg, 'scripts.test:axe' ) ).toBe( 'wp-scripts test-e2e' );
expect( get( pkg, 'scripts.test' ) ).toBe( 'npm run -s test:axe && npm run -s lint' );
} );
/*
TODO: Speed up these tests.
test( 'Installs the wp-theme-auditor dependency', async () => {
const filepath = tempWrite.sync( JSON.stringify( {} ), 'package.json' );
await createWpThemeAuditor( {
cwd: path.dirname( filepath ),
quiet: true,
} );
expect( get( JSON.parse( fs.readFileSync( filepath, 'utf8' ) ), 'devDependencies.wp-theme-auditor' ) ).toBeTruthy();
} );
test( 'Installs the wp-theme-auditor dependency via yarn if there\'s a lockfile', async () => {
const yarnLock = tempWrite.sync( '', 'yarn.lock' );
await createWpThemeAuditor( {
cwd: path.dirname( yarnLock ),
quiet: true,
} );
expect( fs.readFileSync( yarnLock, 'utf8' ) ).toMatch( /wp-theme-auditor/ );
} );
*/