1
1
import sinon from 'sinon' ;
2
2
import { expect } from 'chai' ;
3
3
import StronglyConnectedComponentsBuilder from '../../src/scc' ;
4
+ import ExportMapBuilder from '../../src/exportMap/builder' ;
4
5
5
6
function exportMapFixtureBuilder ( path , imports ) {
6
7
return {
@@ -10,9 +11,7 @@ function exportMapFixtureBuilder(path, imports) {
10
11
}
11
12
12
13
describe ( 'Strongly Connected Components Builder' , ( ) => {
13
- const fakeExportMapBuilder = { for : sinon . spy ( ) } ;
14
- before ( ( ) => StronglyConnectedComponentsBuilder . injectExportMapBuilder ( fakeExportMapBuilder ) ) ;
15
- after ( ( ) => StronglyConnectedComponentsBuilder . resetExportMapBuilder ( ) ) ;
14
+ afterEach ( ( ) => ExportMapBuilder . for . restore ( ) ) ;
16
15
afterEach ( ( ) => StronglyConnectedComponentsBuilder . clearCache ( ) ) ;
17
16
18
17
describe ( 'When getting an SCC' , ( ) => {
@@ -26,7 +25,7 @@ describe('Strongly Connected Components Builder', () => {
26
25
describe ( 'Given two files' , ( ) => {
27
26
describe ( 'When they don\'t cycle' , ( ) => {
28
27
it ( 'Should return foreign SCCs' , ( ) => {
29
- fakeExportMapBuilder . for = sinon . stub ( ) . returns (
28
+ sinon . stub ( ExportMapBuilder , 'for' ) . returns (
30
29
exportMapFixtureBuilder ( 'foo.js' , [ exportMapFixtureBuilder ( 'bar.js' , [ ] ) ] ) ,
31
30
) ;
32
31
const actual = StronglyConnectedComponentsBuilder . for ( source , context ) ;
@@ -36,7 +35,7 @@ describe('Strongly Connected Components Builder', () => {
36
35
37
36
describe ( 'When they do cycle' , ( ) => {
38
37
it ( 'Should return same SCC' , ( ) => {
39
- fakeExportMapBuilder . for = sinon . stub ( ) . returns (
38
+ sinon . stub ( ExportMapBuilder , 'for' ) . returns (
40
39
exportMapFixtureBuilder ( 'foo.js' , [
41
40
exportMapFixtureBuilder ( 'bar.js' , [
42
41
exportMapFixtureBuilder ( 'foo.js' , [ ] ) ,
@@ -53,7 +52,7 @@ describe('Strongly Connected Components Builder', () => {
53
52
describe ( 'When they form a line' , ( ) => {
54
53
describe ( 'When A -> B -> C' , ( ) => {
55
54
it ( 'Should return foreign SCCs' , ( ) => {
56
- fakeExportMapBuilder . for = sinon . stub ( ) . returns (
55
+ sinon . stub ( ExportMapBuilder , 'for' ) . returns (
57
56
exportMapFixtureBuilder ( 'foo.js' , [
58
57
exportMapFixtureBuilder ( 'bar.js' , [
59
58
exportMapFixtureBuilder ( 'buzz.js' , [ ] ) ,
@@ -67,7 +66,7 @@ describe('Strongly Connected Components Builder', () => {
67
66
68
67
describe ( 'When A -> B <-> C' , ( ) => {
69
68
it ( 'Should return 2 SCCs, A on its own' , ( ) => {
70
- fakeExportMapBuilder . for = sinon . stub ( ) . returns (
69
+ sinon . stub ( ExportMapBuilder , 'for' ) . returns (
71
70
exportMapFixtureBuilder ( 'foo.js' , [
72
71
exportMapFixtureBuilder ( 'bar.js' , [
73
72
exportMapFixtureBuilder ( 'buzz.js' , [
@@ -83,7 +82,7 @@ describe('Strongly Connected Components Builder', () => {
83
82
84
83
describe ( 'When A <-> B -> C' , ( ) => {
85
84
it ( 'Should return 2 SCCs, C on its own' , ( ) => {
86
- fakeExportMapBuilder . for = sinon . stub ( ) . returns (
85
+ sinon . stub ( ExportMapBuilder , 'for' ) . returns (
87
86
exportMapFixtureBuilder ( 'foo.js' , [
88
87
exportMapFixtureBuilder ( 'bar.js' , [
89
88
exportMapFixtureBuilder ( 'buzz.js' , [ ] ) ,
@@ -98,7 +97,7 @@ describe('Strongly Connected Components Builder', () => {
98
97
99
98
describe ( 'When A <-> B <-> C' , ( ) => {
100
99
it ( 'Should return same SCC' , ( ) => {
101
- fakeExportMapBuilder . for = sinon . stub ( ) . returns (
100
+ sinon . stub ( ExportMapBuilder , 'for' ) . returns (
102
101
exportMapFixtureBuilder ( 'foo.js' , [
103
102
exportMapFixtureBuilder ( 'bar.js' , [
104
103
exportMapFixtureBuilder ( 'foo.js' , [ ] ) ,
@@ -116,7 +115,7 @@ describe('Strongly Connected Components Builder', () => {
116
115
117
116
describe ( 'When they form a loop' , ( ) => {
118
117
it ( 'Should return same SCC' , ( ) => {
119
- fakeExportMapBuilder . for = sinon . stub ( ) . returns (
118
+ sinon . stub ( ExportMapBuilder , 'for' ) . returns (
120
119
exportMapFixtureBuilder ( 'foo.js' , [
121
120
exportMapFixtureBuilder ( 'bar.js' , [
122
121
exportMapFixtureBuilder ( 'buzz.js' , [
@@ -132,7 +131,7 @@ describe('Strongly Connected Components Builder', () => {
132
131
133
132
describe ( 'When they form a Y' , ( ) => {
134
133
it ( 'Should return 3 distinct SCCs' , ( ) => {
135
- fakeExportMapBuilder . for = sinon . stub ( ) . returns (
134
+ sinon . stub ( ExportMapBuilder , 'for' ) . returns (
136
135
exportMapFixtureBuilder ( 'foo.js' , [
137
136
exportMapFixtureBuilder ( 'bar.js' , [ ] ) ,
138
137
exportMapFixtureBuilder ( 'buzz.js' , [ ] ) ,
@@ -145,7 +144,7 @@ describe('Strongly Connected Components Builder', () => {
145
144
146
145
describe ( 'When they form a Mercedes' , ( ) => {
147
146
it ( 'Should return 1 SCC' , ( ) => {
148
- fakeExportMapBuilder . for = sinon . stub ( ) . returns (
147
+ sinon . stub ( ExportMapBuilder , 'for' ) . returns (
149
148
exportMapFixtureBuilder ( 'foo.js' , [
150
149
exportMapFixtureBuilder ( 'bar.js' , [
151
150
exportMapFixtureBuilder ( 'foo.js' , [ ] ) ,
0 commit comments