Skip to content
This repository was archived by the owner on Aug 17, 2018. It is now read-only.

Commit b03515f

Browse files
authored
Remove source from serializable data structure #5 (#6)
1 parent 072a4af commit b03515f

File tree

6 files changed

+24
-67
lines changed

6 files changed

+24
-67
lines changed

src/__tests__/multiNamed.js

+6-24
Original file line numberDiff line numberDiff line change
@@ -41,24 +41,12 @@ describe('Named multi fixture file', () => {
4141
);
4242
});
4343

44-
it('has source', () => {
45-
expect(fixtures[0].source).toEqual({
46-
name: 'A fix',
47-
component: Bold,
48-
props: {
49-
name: 'Alina'
50-
}
51-
});
44+
it('has fixtureIndex 0', () => {
45+
expect(fixtures[0].fixtureIndex).toBe(0);
5246
});
5347

54-
it('has source', () => {
55-
expect(fixtures[1].source).toEqual({
56-
name: 'S fix',
57-
component: Bold,
58-
props: {
59-
name: 'Sarah'
60-
}
61-
});
48+
it('has fixtureIndex 1', () => {
49+
expect(fixtures[1].fixtureIndex).toBe(1);
6250
});
6351
});
6452

@@ -79,14 +67,8 @@ describe('Named multi fixture file', () => {
7967
);
8068
});
8169

82-
it('has source', () => {
83-
expect(fixtures[0].source).toEqual({
84-
name: 'J fix',
85-
component: Italics,
86-
props: {
87-
name: 'John'
88-
}
89-
});
70+
it('has fixtureIndex 2', () => {
71+
expect(fixtures[0].fixtureIndex).toBe(2);
9072
});
9173
});
9274
});

src/__tests__/multiUnnamed.js

+6-21
Original file line numberDiff line numberDiff line change
@@ -41,22 +41,12 @@ describe('Unnamed multi fixture file', () => {
4141
);
4242
});
4343

44-
it('has source', () => {
45-
expect(fixtures[0].source).toEqual({
46-
component: Bold,
47-
props: {
48-
name: 'Alina'
49-
}
50-
});
44+
it('has fixtureIndex 0', () => {
45+
expect(fixtures[0].fixtureIndex).toBe(0);
5146
});
5247

53-
it('has source', () => {
54-
expect(fixtures[1].source).toEqual({
55-
component: Bold,
56-
props: {
57-
name: 'Sarah'
58-
}
59-
});
48+
it('has fixtureIndex 1', () => {
49+
expect(fixtures[1].fixtureIndex).toBe(1);
6050
});
6151
});
6252

@@ -77,13 +67,8 @@ describe('Unnamed multi fixture file', () => {
7767
);
7868
});
7969

80-
it('has source', () => {
81-
expect(fixtures[0].source).toEqual({
82-
component: Italics,
83-
props: {
84-
name: 'John'
85-
}
86-
});
70+
it('has fixtureIndex 2', () => {
71+
expect(fixtures[0].fixtureIndex).toBe(2);
8772
});
8873
});
8974
});

src/__tests__/singleNamed.js

+2-8
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,7 @@ describe('Named single fixture file', () => {
2323
);
2424
});
2525

26-
it('has fixture source', () => {
27-
expect(components[0].fixtures[0].source).toEqual({
28-
component: Italics,
29-
name: 'foo fixture',
30-
props: {
31-
name: 'John'
32-
}
33-
});
26+
it('has null fixtureIndex', () => {
27+
expect(components[0].fixtures[0].fixtureIndex).toBe(null);
3428
});
3529
});

src/__tests__/singleUnnamed.js

+2-7
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,7 @@ describe('Unnamed single fixture file', () => {
2323
);
2424
});
2525

26-
it('has fixture source', () => {
27-
expect(components[0].fixtures[0].source).toEqual({
28-
component: Italics,
29-
props: {
30-
name: 'John'
31-
}
32-
});
26+
it('has null fixtureIndex', () => {
27+
expect(components[0].fixtures[0].fixtureIndex).toBe(null);
3328
});
3429
});

src/getComponents.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ export async function getComponents(args: Args): Promise<Components> {
6262
// Can't use forEach because we want each (async) loop to be serial
6363
for (let j = 0; j < fixturesInFile.length; j++) {
6464
const fixture = fixturesInFile[j];
65+
const fixtureIndex = isMultiFixture ? j : null;
6566
const { component, name } = fixture;
6667

6768
// TODO: Throw if fixture.component is missing
@@ -79,9 +80,9 @@ export async function getComponents(args: Args): Promise<Components> {
7980

8081
compFixtures.push({
8182
filePath: fixturePath,
83+
fixtureIndex,
8284
name: name || defaultFixtureNamer(component),
83-
namespace,
84-
source: fixture
85+
namespace
8586
});
8687

8788
if (!componentPaths.get(component)) {
@@ -90,7 +91,7 @@ export async function getComponents(args: Args): Promise<Components> {
9091
componentPath
9192
} = await getComponentInfoFromFixture({
9293
fixturePath,
93-
fixtureIndex: isMultiFixture ? j : null
94+
fixtureIndex
9495
});
9596

9697
// It's possible to identify the component name but not the file path

src/types.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,20 @@
33
import type { ComponentType } from 'react';
44

55
export type Fixture = {
6-
name: string,
7-
namespace: string,
86
filePath: string,
9-
source: Object
7+
fixtureIndex: number | null,
8+
name: string,
9+
namespace: string
1010
};
1111

1212
export type Fixtures = Array<Fixture>;
1313

1414
export type FixturesByComponent = Map<ComponentType<*>, Fixtures>;
1515

1616
export type Component = {
17+
filePath: string | null,
1718
name: string,
1819
namespace: string,
19-
filePath: string | null,
2020
type: ComponentType<*>,
2121
fixtures: Fixtures
2222
};

0 commit comments

Comments
 (0)