-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Expand file tree
/
Copy pathproject_utils_spec.ts
More file actions
95 lines (82 loc) · 2.69 KB
/
project_utils_spec.ts
File metadata and controls
95 lines (82 loc) · 2.69 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
import Chai from 'chai'
import path from 'path'
import { getSpecUrl } from '../../lib/project_utils'
import Fixtures from '@tooling/system-tests'
const todosPath = Fixtures.projectPath('todos')
const defaultProps: Parameters<typeof getSpecUrl>[0] = {
browserUrl: 'http://localhost:8888/__/',
projectRoot: todosPath,
spec: {
name: 'cypress/integration/foo/bar.js',
relative: 'cypress/integration/foo/bar.js',
absolute: '/bin/cypress/integration/foo/bar.js',
},
}
const expect = Chai.expect
describe('lib/project_utils', () => {
describe('getSpecUrl', () => {
it('returns fully qualified url when spec exists', function () {
const str = getSpecUrl({
...defaultProps,
spec: {
...defaultProps.spec,
},
})
expect(str).to.eq('http://localhost:8888/__/#/specs/runner?file=cypress/integration/foo/bar.js')
})
it('returns fully qualified url on absolute path to spec', function () {
const todosSpec = path.join(todosPath, 'tests/sub/sub_test.coffee')
const str = getSpecUrl({
...defaultProps,
spec: {
...defaultProps.spec,
relative: 'tests/sub/sub_test.coffee',
name: 'tests/sub/sub_test.coffee',
absolute: todosSpec,
},
})
expect(str).to.eq('http://localhost:8888/__/#/specs/runner?file=tests/sub/sub_test.coffee')
})
it('escapses %, &', function () {
const rel = 'tests/sub/a&b%c.js'
const todosSpec = path.join(todosPath, rel)
const str = getSpecUrl({
...defaultProps,
spec: {
name: rel,
relative: rel,
absolute: todosSpec,
},
})
expect(str).to.eq('http://localhost:8888/__/#/specs/runner?file=tests/sub/a%26b%25c.js')
})
// ? is invalid in Windows, but it can be tested here
// because it's a unit test and doesn't check the existence of files
it('escapes ?', function () {
const rel = 'tests/sub/a?.spec.js'
const todosSpec = path.join(todosPath, rel)
const str = getSpecUrl({
...defaultProps,
spec: {
name: rel,
relative: rel,
absolute: todosSpec,
},
})
expect(str).to.eq('http://localhost:8888/__/#/specs/runner?file=tests/sub/a%3F.spec.js')
})
it('escapes %, &, ? in the url dir', function () {
const rel = 'tests/s%&?ub/a.spec.js'
const todosSpec = path.join(todosPath, rel)
const str = getSpecUrl({
...defaultProps,
spec: {
absolute: todosSpec,
relative: rel,
name: rel,
},
})
expect(str).to.eq('http://localhost:8888/__/#/specs/runner?file=tests/s%25%26%3Fub/a.spec.js')
})
})
})