Skip to content
This repository has been archived by the owner on Nov 8, 2024. It is now read-only.

Commit

Permalink
test: speedup tests
Browse files Browse the repository at this point in the history
Close #1217
  • Loading branch information
honzajavorek authored and kylef committed Feb 1, 2019
1 parent c662d7c commit 4e9ecae
Show file tree
Hide file tree
Showing 15 changed files with 138 additions and 113 deletions.
6 changes: 3 additions & 3 deletions test/integration/cli/api-blueprint-cli-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ describe('CLI - API Blueprint Document', () => {
let runtimeInfo;
const args = ['./test/fixtures/single-get.apib', `http://127.0.0.1:${DEFAULT_SERVER_PORT}`];

beforeEach((done) => {
before((done) => {
const app = createServer();
app.get('/machines', (req, res) => res.json([{ type: 'bulldozer', name: 'willy' }]));

Expand All @@ -29,7 +29,7 @@ describe('CLI - API Blueprint Document', () => {
`http://127.0.0.1:${DEFAULT_SERVER_PORT}`,
];

beforeEach((done) => {
before((done) => {
const app = createServer();
runCLIWithServer(args, app, (err, info) => {
runtimeInfo = info;
Expand All @@ -49,7 +49,7 @@ describe('CLI - API Blueprint Document', () => {
'--no-color',
];

beforeEach((done) => {
before((done) => {
const app = createServer();
runCLIWithServer(args, app, (err, info) => {
runtimeInfo = info;
Expand Down
22 changes: 11 additions & 11 deletions test/integration/cli/api-description-cli-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe('CLI - API Description Document', () => {
let runtimeInfo;
const args = ['./test/fixtures/single-g*t.apib', `http://127.0.0.1:${DEFAULT_SERVER_PORT}`];

beforeEach((done) => {
before((done) => {
const app = createServer();
app.get('/machines', (req, res) => res.json([{ type: 'bulldozer', name: 'willy' }]));

Expand All @@ -33,7 +33,7 @@ describe('CLI - API Description Document', () => {
`http://127.0.0.1:${DEFAULT_SERVER_PORT}`,
];

beforeEach((done) => {
before((done) => {
const app = createServer();
runCLIWithServer(args, app, (err, info) => {
runtimeInfo = info;
Expand All @@ -52,7 +52,7 @@ describe('CLI - API Description Document', () => {
`http://127.0.0.1:${DEFAULT_SERVER_PORT}`,
];

beforeEach((done) => {
before((done) => {
const app = createServer();
runCLIWithServer(args, app, (err, info) => {
runtimeInfo = info;
Expand All @@ -74,7 +74,7 @@ describe('CLI - API Description Document', () => {
`http://127.0.0.1:${DEFAULT_SERVER_PORT}`,
];

beforeEach((done) => {
before((done) => {
const app = createServer();
app.get('/single-get.apib', (req, res) => {
res.type('text/vnd.apiblueprint');
Expand All @@ -100,7 +100,7 @@ describe('CLI - API Description Document', () => {
`http://127.0.0.1:${DEFAULT_SERVER_PORT}`,
];

beforeEach((done) => {
before((done) => {
const app = createServer();
runCLIWithServer(args, app, (err, info) => {
runtimeInfo = info;
Expand All @@ -124,7 +124,7 @@ describe('CLI - API Description Document', () => {
`http://127.0.0.1:${DEFAULT_SERVER_PORT}`,
];

beforeEach((done) => {
before((done) => {
const app = createServer();
app.get('/__non-existent__.apib', (req, res) => res.sendStatus(404));

Expand Down Expand Up @@ -154,7 +154,7 @@ describe('CLI - API Description Document', () => {
'--path=./test/fixtures/single-get-uri-template.apib',
];

beforeEach((done) => {
before((done) => {
const app = createServer();
app.get('/machines', (req, res) => res.json([{ type: 'bulldozer', name: 'willy' }]));
app.get('/machines/willy', (req, res) => res.json({ type: 'bulldozer', name: 'willy' }));
Expand All @@ -177,7 +177,7 @@ describe('CLI - API Description Document', () => {
`--path=http://127.0.0.1:${DEFAULT_SERVER_PORT}/single-get.yaml`,
];

beforeEach((done) => {
before((done) => {
const app = createServer();
app.get('/single-get.yaml', (req, res) => {
res.type('application/yaml');
Expand Down Expand Up @@ -206,7 +206,7 @@ describe('CLI - API Description Document', () => {
'--path=./test/fixtures/single-get-path.apib',
];

beforeEach((done) => {
before((done) => {
const app = createServer();
app.get('/machines', (req, res) => res.json([{ type: 'bulldozer', name: 'willy' }]));
app.get('/machines/willy', (req, res) => res.json({ type: 'bulldozer', name: 'willy' }));
Expand All @@ -230,7 +230,7 @@ describe('CLI - API Description Document', () => {
'--path=./test/fixtures/single-get-uri-temp*.apib',
];

beforeEach((done) => {
before((done) => {
const app = createServer();
app.get('/machines', (req, res) => res.json([{ type: 'bulldozer', name: 'willy' }]));
app.get('/machines/willy', (req, res) => res.json({ type: 'bulldozer', name: 'willy' }));
Expand All @@ -253,7 +253,7 @@ describe('CLI - API Description Document', () => {
'--path=./test/fixtures/__non-existent__.apib',
];

beforeEach((done) => {
before((done) => {
const app = createServer();
app.get('/machines', (req, res) => res.json([{ type: 'bulldozer', name: 'willy' }]));

Expand Down
6 changes: 3 additions & 3 deletions test/integration/cli/openapi2-cli-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ describe('CLI - OpenAPI 2 Document', () => {
let runtimeInfo;
const args = ['./test/fixtures/single-get.yaml', `http://127.0.0.1:${DEFAULT_SERVER_PORT}`];

beforeEach((done) => {
before((done) => {
const app = createServer();
app.get('/machines', (req, res) => res.json([{ type: 'bulldozer', name: 'willy' }]));

Expand All @@ -29,7 +29,7 @@ describe('CLI - OpenAPI 2 Document', () => {
`http://127.0.0.1:${DEFAULT_SERVER_PORT}`,
];

beforeEach((done) => {
before((done) => {
const app = createServer();
runCLIWithServer(args, app, (err, info) => {
runtimeInfo = info;
Expand All @@ -49,7 +49,7 @@ describe('CLI - OpenAPI 2 Document', () => {
'--no-color',
];

beforeEach((done) => {
before((done) => {
const app = createServer();
app.get('/machines', (req, res) => res.json([{ type: 'bulldozer', name: 'willy' }]));

Expand Down
42 changes: 23 additions & 19 deletions test/integration/cli/reporters-cli-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const APIARY_PORT = DEFAULT_SERVER_PORT + 1;
describe('CLI - Reporters', () => {
let server;

beforeEach((done) => {
before((done) => {
const app = createServer();

app.get('/machines', (req, res) => res.json([{ type: 'bulldozer', name: 'willy' }]));
Expand All @@ -19,7 +19,7 @@ describe('CLI - Reporters', () => {
});
});

afterEach(done => server.close(done));
after(done => server.close(done));


describe('when -r/--reporter is provided to use additional reporters', () => {
Expand All @@ -30,7 +30,7 @@ describe('CLI - Reporters', () => {
'--reporter=nyan',
];

beforeEach((done) => {
before((done) => {
runCLI(args, (err, info) => {
cliInfo = info;
done(err);
Expand All @@ -51,7 +51,7 @@ describe('CLI - Reporters', () => {
const env = clone(process.env);
env.APIARY_API_URL = `http://127.0.0.1:${APIARY_PORT}`;

beforeEach((done) => {
before((done) => {
const app = createServer();

app.post('/apis/*', (req, res) => {
Expand All @@ -70,7 +70,7 @@ describe('CLI - Reporters', () => {
});
});

afterEach(done => apiary.close(done));
after(done => apiary.close(done));

describe('when Dredd successfully performs requests to Apiary', () => {
let cliInfo;
Expand All @@ -81,11 +81,14 @@ describe('CLI - Reporters', () => {
'--reporter=apiary',
];

beforeEach(done => runCLI(args, { env }, (err, info) => {
cliInfo = info;
stepRequest = apiaryRuntimeInfo.requests['/apis/public/tests/steps?testRunId=1234_id'][0];
done(err);
}));
before((done) => {
apiaryRuntimeInfo.reset();
runCLI(args, { env }, (err, info) => {
cliInfo = info;
stepRequest = apiaryRuntimeInfo.requests['/apis/public/tests/steps?testRunId=1234_id'][0];
done(err);
});
});

it('should print URL of the test report', () => assert.include(cliInfo.stdout, 'http://example.com/test/run/1234_id'));
it('should print warning about missing Apiary API settings', () => assert.include(cliInfo.stdout, 'Apiary API Key or API Project Subdomain were not provided.'));
Expand Down Expand Up @@ -120,7 +123,8 @@ describe('CLI - Reporters', () => {
'--hookfiles=./test/fixtures/hooks-log.coffee',
];

beforeEach((done) => {
before((done) => {
apiaryRuntimeInfo.reset();
runCLI(args, { env }, (err, info) => {
cliInfo = info;
updateRequest = apiaryRuntimeInfo.requests['/apis/public/tests/run/1234_id'][0];
Expand Down Expand Up @@ -193,11 +197,11 @@ describe('CLI - Reporters', () => {
'--output=__test_file_output__.xml',
];

beforeEach(done => runCLI(args, (err) => {
before(done => runCLI(args, (err) => {
done(err);
}));

afterEach(() => fs.unlinkSync(`${process.cwd()}/__test_file_output__.xml`));
after(() => fs.unlinkSync(`${process.cwd()}/__test_file_output__.xml`));

it('should create given file', () => assert.isOk(fs.existsSync(`${process.cwd()}/__test_file_output__.xml`)));
});
Expand All @@ -212,11 +216,11 @@ describe('CLI - Reporters', () => {
'--output=__test_file_output2__.xml',
];

beforeEach(done => runCLI(args, (err) => {
before(done => runCLI(args, (err) => {
done(err);
}));

afterEach(() => {
after(() => {
fs.unlinkSync(`${process.cwd()}/__test_file_output1__.xml`);
fs.unlinkSync(`${process.cwd()}/__test_file_output2__.xml`);
});
Expand All @@ -235,7 +239,7 @@ describe('CLI - Reporters', () => {
'--output=./__test_directory/__test_file_output__.xml',
];

beforeEach((done) => {
before((done) => {
try {
fs.unlinkSync(`${process.cwd()}/__test_directory/__test_file_output__.xml`);
} catch (error) {
Expand All @@ -247,7 +251,7 @@ describe('CLI - Reporters', () => {
});
});

afterEach(() => {
after(() => {
fs.unlinkSync(`${process.cwd()}/__test_directory/__test_file_output__.xml`);
fs.rmdirSync(`${process.cwd()}/__test_directory`);
});
Expand All @@ -264,7 +268,7 @@ describe('CLI - Reporters', () => {
'--reporter=apiary',
];

beforeEach((done) => {
before((done) => {
apiaryApiUrl = process.env.APIARY_API_URL;

const nonExistentPort = DEFAULT_SERVER_PORT + 42;
Expand All @@ -275,7 +279,7 @@ describe('CLI - Reporters', () => {
done(err);
});
});
afterEach(() => { process.env.APIARY_API_URL = apiaryApiUrl; });
after(() => { process.env.APIARY_API_URL = apiaryApiUrl; });

it('ends successfully', () => assert.equal(cliInfo.exitStatus, 0));
it('prints error about Apiary API connection issues', () => assert.include(cliInfo.stderr, 'Apiary reporter could not connect to Apiary API'));
Expand Down
16 changes: 8 additions & 8 deletions test/integration/cli/server-process-cli-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe('CLI - Server Process', () => {
let server;
let serverRuntimeInfo;

beforeEach((done) => {
before((done) => {
const app = createServer();

app.get('/machines', (req, res) => res.json([{ type: 'bulldozer', name: 'willy' }]));
Expand All @@ -23,14 +23,14 @@ describe('CLI - Server Process', () => {
});
});

afterEach(done => server.close(done));
after(done => server.close(done));


describe('when is running', () => {
let cliInfo;
const args = ['./test/fixtures/single-get.apib', `http://127.0.0.1:${DEFAULT_SERVER_PORT}`];

beforeEach(done => runCLI(args, (err, info) => {
before(done => runCLI(args, (err, info) => {
cliInfo = info;
done(err);
}));
Expand All @@ -43,7 +43,7 @@ describe('CLI - Server Process', () => {
let cliInfo;
const args = ['./test/fixtures/apiary.apib', `http://127.0.0.1:${NON_EXISTENT_PORT}`];

beforeEach(done => runCLI(args, (err, info) => {
before(done => runCLI(args, (err, info) => {
cliInfo = info;
done(err);
}));
Expand Down Expand Up @@ -71,7 +71,7 @@ describe('CLI - Server Process', () => {
'--server-wait=1',
];

beforeEach(done => runCLI(args, (err, info) => {
before(done => runCLI(args, (err, info) => {
cliInfo = info;
done(err);
}));
Expand All @@ -90,7 +90,7 @@ describe('CLI - Server Process', () => {
'--server-wait=1',
];

beforeEach(done => runCLI(args, (err, info) => {
before(done => runCLI(args, (err, info) => {
cliInfo = info;
done(err);
}));
Expand Down Expand Up @@ -134,7 +134,7 @@ describe('CLI - Server Process', () => {
'--server-wait=1',
];

beforeEach(done => runCLI(args, (err, info) => {
before(done => runCLI(args, (err, info) => {
cliInfo = info;
done(err);
}));
Expand Down Expand Up @@ -162,7 +162,7 @@ describe('CLI - Server Process', () => {
'--level=verbose',
];

beforeEach(done => runCLI(args, (err, info) => {
before(done => runCLI(args, (err, info) => {
cliInfo = info;
done(err);
}));
Expand Down
2 changes: 1 addition & 1 deletion test/integration/dredd-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ describe('Dredd class Integration', () => {
const reTransactionName = /hook: (.+)/g;
let matches;

beforeEach(done => execCommand({
before(done => execCommand({
options: {
path: './test/fixtures/multiple-responses.yaml',
hookfiles: './test/fixtures/openapi2-transaction-names.js',
Expand Down
7 changes: 7 additions & 0 deletions test/integration/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,13 @@ function createServer(options = {}) {
lastRequest: null,
requests: {},
requestCounts: {},
reset: function reset() {
this.requestedOnce = false;
this.requested = false;
this.lastRequest = null;
this.requests = {};
this.requestCounts = {};
},
};

let app = express();
Expand Down
Loading

0 comments on commit 4e9ecae

Please sign in to comment.