Skip to content

Commit

Permalink
(tests): Re-enable file upload tests for Node.js 10. 馃帀馃帀馃帀
Browse files Browse the repository at this point in the history
This commit again looks quite complicated, but's merely an over-complication
inflicted by Prettification.  Disabling whitespace differences when viewing
this commit, the functional change here is that we no longer skip many file
upload tests when the (semver) major segment of `process.version` is `10`.

I couldn't be happier to get rid of this exception for file upload tests on
Node.js 10, which was an unfortunate reality of the non-updated
`graphql-upload` module world we previously lived in.
  • Loading branch information
abernix committed Nov 30, 2018
1 parent cd6e575 commit bc975c9
Show file tree
Hide file tree
Showing 3 changed files with 194 additions and 193 deletions.
126 changes: 63 additions & 63 deletions packages/apollo-server-express/src/__tests__/ApolloServer.test.ts
Expand Up @@ -427,48 +427,47 @@ describe('apollo-server-express', () => {
});
});
});
// NODE: Intentionally skip file upload tests on Node.js 10.
// Also skip Node.js 6, but only because `graphql-upload`
// NODE: 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!
}
(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 @@ -477,35 +476,36 @@ describe('apollo-server-express', () => {
}
}
`,
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);
variables: {
file: null,
},
}),
);

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
126 changes: 63 additions & 63 deletions packages/apollo-server-koa/src/__tests__/ApolloServer.test.ts
Expand Up @@ -323,48 +323,47 @@ describe('apollo-server-koa', () => {
});
});
});
// NODE: Intentionally skip file upload tests on Node.js 10.
// Also skip Node.js 6, but only because `graphql-upload`
// NODE: 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!
}
(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 @@ -373,35 +372,36 @@ describe('apollo-server-koa', () => {
}
}
`,
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);
variables: {
file: null,
},
}),
);

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 bc975c9

Please sign in to comment.