-
Notifications
You must be signed in to change notification settings - Fork 4
/
test.js
105 lines (86 loc) · 2.48 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
98
99
100
101
102
103
104
105
// @flow
'use strict';
const {
resolveFilePathAsync,
resolveFilePathSync,
resolveImportFilePathAsync,
resolveImportFilePathSync,
loadFileAsync,
loadFileSync,
loadImportAsync,
loadImportSync,
} = require('./');
const path = require('path');
const createFile = require('babel-file');
let isFile = (fileName, cb) => cb(null, true);
let isFileSync = fileName => true;
test('resolveFilePathAsync()', () => {
let file = createFile('foo;', {
filename: 'foo.js',
});
return resolveFilePathAsync(file.path, './bar.js', {
isFile: isFile,
}).then(result => {
expect(result).toMatch(/\/bar\.js$/)
});
});
test('resolveFilePathSync()', () => {
let file = createFile('foo;', {
filename: 'foo.js',
});
let result = resolveFilePathSync(file.path, './bar.js', {
isFile: isFileSync,
});
expect(result).toMatch(/\/bar\.js$/);
});
test('resolveImportFilePathAsync()', () => {
let file = createFile('import "./bar";', {
filename: 'foo.js',
});
let importDeclaration = file.path.get('body')[0];
return resolveImportFilePathAsync(importDeclaration, {
isFile: isFile,
}).then(result => {
expect(result).toMatch(/\/bar$/)
});
});
test('resolveImportFilePathSync()', () => {
let file = createFile('import "./bar";', {
filename: 'foo.js',
});
let importDeclaration = file.path.get('body')[0];
let result = resolveImportFilePathSync(importDeclaration, {
isFile: isFileSync,
});
expect(result).toMatch(/\/bar$/);
});
test('loadFileAsync()', () => {
return loadFileAsync('fixture.js').then(result => {
expect(result.code).toContain('// fixture');
expect(result).toHaveProperty('path');
});
});
test('loadFileSync()', () => {
let result = loadFileSync('fixture.js');
expect(result.code).toContain('// fixture');
expect(result).toHaveProperty('path');
});
test('loadImportAsync()', () => {
let file = createFile('import "./fixture";', {
filename: path.join(__dirname, 'test.js'),
});
let importDeclaration = file.path.get('body')[0];
return loadImportAsync(importDeclaration).then(result => {
expect(result.code).toContain('// fixture');
expect(result).toHaveProperty('path');
});
});
test('loadImportSync()', () => {
let file = createFile('import "./fixture";', {
filename: path.join(__dirname, 'test.js'),
});
let importDeclaration = file.path.get('body')[0];
let result = loadImportSync(importDeclaration);
expect(result.code).toContain('// fixture');
expect(result).toHaveProperty('path');
});