Skip to content

Commit

Permalink
(tests) Skip file upload tests for NODE_MAJOR_VERSION === 6.
Browse files Browse the repository at this point in the history
This commit looks way more complicated than it really is thanks to Prettier
trying to be helpful.

All I've done is add `NODE_MAJOR_VERSION === 6` as a version NOT to test
uploads for, in an effort to fix the failing tests (failing appropriately
since Node.js 6 with file uploads throws an error right now and cannot run
uploads anymore.).
  • Loading branch information
abernix committed Nov 30, 2018
1 parent 6dc132e commit cd6e575
Show file tree
Hide file tree
Showing 3 changed files with 195 additions and 192 deletions.
125 changes: 63 additions & 62 deletions packages/apollo-server-express/src/__tests__/ApolloServer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -428,45 +428,47 @@ describe('apollo-server-express', () => {
});
});
// NODE: Intentionally skip file upload tests on Node.js 10.
(NODE_MAJOR_VERSION === 10 ? describe.skip : describe)(
'file uploads',
() => {
it('enabled uploads', async () => {
const { port } = await createServer({
typeDefs: gql`
type File {
filename: String!
mimetype: String!
encoding: String!
}
// Also skip Node.js 6, but only because `graphql-upload`
// doesn't support it.
(NODE_MAJOR_VERSION === 10 || NODE_MAJOR_VERSION === 6
? describe.skip
: describe)('file uploads', () => {
it('enabled uploads', async () => {
const { port } = await createServer({
typeDefs: gql`
type File {
filename: String!
mimetype: String!
encoding: String!
}
type Query {
uploads: [File]
}
type Query {
uploads: [File]
}
type Mutation {
singleUpload(file: Upload!): File!
}
`,
resolvers: {
Query: {
uploads: () => {},
},
Mutation: {
singleUpload: async (_, args) => {
expect((await args.file).stream).toBeDefined();
return args.file;
},
type Mutation {
singleUpload(file: Upload!): File!
}
`,
resolvers: {
Query: {
uploads: () => {},
},
Mutation: {
singleUpload: async (_, args) => {
expect((await args.file).stream).toBeDefined();
return args.file;
},
},
});
},
});

const body = new FormData();
const body = new FormData();

body.append(
'operations',
JSON.stringify({
query: `
body.append(
'operations',
JSON.stringify({
query: `
mutation($file: Upload!) {
singleUpload(file: $file) {
filename
Expand All @@ -475,36 +477,35 @@ describe('apollo-server-express', () => {
}
}
`,
variables: {
file: null,
},
}),
);
variables: {
file: null,
},
}),
);

body.append('map', JSON.stringify({ 1: ['variables.file'] }));
body.append('1', fs.createReadStream('package.json'));

try {
const resolved = await fetch(`http://localhost:${port}/graphql`, {
method: 'POST',
body: body as any,
});
const text = await resolved.text();
const response = JSON.parse(text);

expect(response.data.singleUpload).toEqual({
filename: 'package.json',
encoding: '7bit',
mimetype: 'application/json',
});
} catch (error) {
// This error began appearing randomly and seems to be a dev dependency bug.
// https://github.com/jaydenseric/apollo-upload-server/blob/18ecdbc7a1f8b69ad51b4affbd986400033303d4/test.js#L39-L42
if (error.code !== 'EPIPE') throw error;
}
});
},
);
body.append('map', JSON.stringify({ 1: ['variables.file'] }));
body.append('1', fs.createReadStream('package.json'));

try {
const resolved = await fetch(`http://localhost:${port}/graphql`, {
method: 'POST',
body: body as any,
});
const text = await resolved.text();
const response = JSON.parse(text);

expect(response.data.singleUpload).toEqual({
filename: 'package.json',
encoding: '7bit',
mimetype: 'application/json',
});
} catch (error) {
// This error began appearing randomly and seems to be a dev dependency bug.
// https://github.com/jaydenseric/apollo-upload-server/blob/18ecdbc7a1f8b69ad51b4affbd986400033303d4/test.js#L39-L42
if (error.code !== 'EPIPE') throw error;
}
});
});

describe('errors', () => {
it('returns thrown context error as a valid graphql result', async () => {
Expand Down
125 changes: 63 additions & 62 deletions packages/apollo-server-koa/src/__tests__/ApolloServer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,45 +324,47 @@ describe('apollo-server-koa', () => {
});
});
// NODE: Intentionally skip file upload tests on Node.js 10.
(NODE_MAJOR_VERSION === 10 ? describe.skip : describe)(
'file uploads',
() => {
it('enabled uploads', async () => {
const { port } = await createServer({
typeDefs: gql`
type File {
filename: String!
mimetype: String!
encoding: String!
}
// Also skip Node.js 6, but only because `graphql-upload`
// doesn't support it anymore.
(NODE_MAJOR_VERSION === 10 || NODE_MAJOR_VERSION === 6
? describe.skip
: describe)('file uploads', () => {
it('enabled uploads', async () => {
const { port } = await createServer({
typeDefs: gql`
type File {
filename: String!
mimetype: String!
encoding: String!
}
type Query {
uploads: [File]
}
type Query {
uploads: [File]
}
type Mutation {
singleUpload(file: Upload!): File!
}
`,
resolvers: {
Query: {
uploads: () => {},
},
Mutation: {
singleUpload: async (_, args) => {
expect((await args.file).stream).toBeDefined();
return args.file;
},
type Mutation {
singleUpload(file: Upload!): File!
}
`,
resolvers: {
Query: {
uploads: () => {},
},
Mutation: {
singleUpload: async (_, args) => {
expect((await args.file).stream).toBeDefined();
return args.file;
},
},
});
},
});

const body = new FormData();
const body = new FormData();

body.append(
'operations',
JSON.stringify({
query: `
body.append(
'operations',
JSON.stringify({
query: `
mutation($file: Upload!) {
singleUpload(file: $file) {
filename
Expand All @@ -371,36 +373,35 @@ describe('apollo-server-koa', () => {
}
}
`,
variables: {
file: null,
},
}),
);
variables: {
file: null,
},
}),
);

body.append('map', JSON.stringify({ 1: ['variables.file'] }));
body.append('1', fs.createReadStream('package.json'));

try {
const resolved = await fetch(`http://localhost:${port}/graphql`, {
method: 'POST',
body: body as any,
});
const text = await resolved.text();
const response = JSON.parse(text);

expect(response.data.singleUpload).toEqual({
filename: 'package.json',
encoding: '7bit',
mimetype: 'application/json',
});
} catch (error) {
// This error began appearing randomly and seems to be a dev dependency bug.
// https://github.com/jaydenseric/apollo-upload-server/blob/18ecdbc7a1f8b69ad51b4affbd986400033303d4/test.js#L39-L42
if (error.code !== 'EPIPE') throw error;
}
});
},
);
body.append('map', JSON.stringify({ 1: ['variables.file'] }));
body.append('1', fs.createReadStream('package.json'));

try {
const resolved = await fetch(`http://localhost:${port}/graphql`, {
method: 'POST',
body: body as any,
});
const text = await resolved.text();
const response = JSON.parse(text);

expect(response.data.singleUpload).toEqual({
filename: 'package.json',
encoding: '7bit',
mimetype: 'application/json',
});
} catch (error) {
// This error began appearing randomly and seems to be a dev dependency bug.
// https://github.com/jaydenseric/apollo-upload-server/blob/18ecdbc7a1f8b69ad51b4affbd986400033303d4/test.js#L39-L42
if (error.code !== 'EPIPE') throw error;
}
});
});

describe('errors', () => {
it('returns thrown context error as a valid graphql result', async () => {
Expand Down

0 comments on commit cd6e575

Please sign in to comment.