azure-tests
(Beta)
Helper lib - azure integration tests
prerequisites
- ability to run tests using jest
installation
npm install @spartez-software/azure-test --save-dev
setup
- go get yourself an Azure devOps instance
- setup .env
TEST_AZURE_URL=https://dev.azure.com/your-azure-site-name
TEST_AZURE_USER_TOKEN=pst! it is a secret pat, it belongs to the user that we use to make changes in Azure!
usage (jest/typescript example)
import { step } from '@spartez-software/test-utils';
import { TeamProjectReference } from 'azure-devops-node-api/interfaces/CoreInterfaces';
import { WorkItem } from 'azure-devops-node-api/interfaces/WorkItemTrackingInterfaces';
import { AzureDevOps } from '@spartez-software/azure-test/AzureDevOps';
describe('azure tests', () => {
const azureDevOps = AzureDevOps.fromEnv();
let teamProjectReference: TeamProjectReference;
jest.retryTimes(5);
jest.setTimeout(240000);
beforeEach(async () => {
await step('Create azure Project', async () => {
teamProjectReference = await azureDevOps.createProject();
expect(teamProjectReference).toBeDefined();
});
});
it('should create and destroy project', async () => {
const projectId = String(teamProjectReference.id);
const workItemTrackingApi = await azureDevOps.connection.getWorkItemTrackingApi();
const json = [{
op: 'add',
path: '/fields/System.Title',
from: null,
value: 'Sample task',
}];
let wi: WorkItem;
await step('Create work item', async () => {
wi = await workItemTrackingApi.createWorkItem({}, json, projectId, 'Task');
expect(wi).toBeDefined();
});
await step('Verify workitem exists', async () => {
const workItem = await workItemTrackingApi.getWorkItem(wi.id as number);
expect(workItem).toBeDefined();
});
});
afterEach(async () => {
await step('Delete azure project', async () => {
if (teamProjectReference.id) {
await azureDevOps.deleteProject(teamProjectReference.id);
}
});
});
});
pitfalls
- Azure DevOps can take a long time to create a project, set up timeouts accordingly.
- Large number of project, even deleted ones, make the create project time even longer.