Skip to content

Commit

Permalink
Merge pull request #937 from contentful/improve-integration-tests
Browse files Browse the repository at this point in the history
Fix integration & e2e tests
  • Loading branch information
damienxy committed Oct 26, 2021
2 parents aa673a7 + 8c7cea7 commit 815d08b
Show file tree
Hide file tree
Showing 23 changed files with 45 additions and 44 deletions.
8 changes: 4 additions & 4 deletions .circleci/config.yml
Expand Up @@ -20,7 +20,7 @@ jobs:
- run:
name: Check Delaration
command: |
npm run test-typescript-declaration
npm run test:typescript-declaration
test-unit:
docker:
- image: circleci/node:14
Expand All @@ -32,7 +32,7 @@ jobs:
- run:
name: Run Unit Tests
command: |
npm run test-unit
npm run test:unit
test-integration:
docker:
Expand All @@ -45,7 +45,7 @@ jobs:
- run:
name: Run Integration Tests
command: |
npm run test-integration
npm run test:integration
test-e2e:
docker:
Expand All @@ -58,7 +58,7 @@ jobs:
- run:
name: Run E2E Tests
command: |
npm run test-e2e
npm run test:e2e
release:
docker:
Expand Down
8 changes: 4 additions & 4 deletions CONTRIBUTING.md
Expand Up @@ -16,12 +16,12 @@ Don't worry if this is your first time with Typescript. The language reads like

In order to run integration tests, you need:

* a source space the tests are run against (`CONTENTFUL_INTEGRATION_SOURCE_SPACE`) and is called `Migrations CLI Test`
* a management token for the defined space (`CONTENTFUL_INTEGRATION_MANAGEMENT_TOKEN`)
* a source space the tests are run against (`CONTENTFUL_SPACE_ID`) and is called `contentful-migration`
* a management token for the defined space (`CONTENTFUL_INTEGRATION_TEST_CMA_TOKEN`)

```sh
CONTENTFUL_INTEGRATION_SOURCE_SPACE=<spaceId> \
CONTENTFUL_INTEGRATION_MANAGEMENT_TOKEN=CFPAT-xxx \
CONTENTFUL_SPACE_ID=<spaceId> \
CONTENTFUL_INTEGRATION_TEST_CMA_TOKEN=CFPAT-xxx \
npm test
```

18 changes: 9 additions & 9 deletions package.json
Expand Up @@ -26,18 +26,18 @@
"build": "npm run clean && tsc -p tsconfig.json",
"build-dev": "npm run clean && tsc -p tsconfig-dev.json",
"prepare": "npm run build",
"test": "NOCK_RECORD=0 npm run build && npm run test-unit && npm run test-integration && npm run test-e2e && npm run lint && npm run test-typescript-declaration",
"test-watch": "npm run test-unit -- --watch",
"test-unit": "NODE_ENV=test mocha --require test/setup-unit.js --recursive 'test/unit/**/**/*.spec.{js,ts}'",
"test-integration": "NODE_ENV=test mocha --require test/integration/setup.js 'test/integration/**/*.spec.js'",
"test-e2e": "NODE_ENV=test mocha 'test/end-to-end/**/*.spec.js'",
"test-typescript-declaration": "tsc --strict --noEmit index.d.ts",
"test": "NOCK_RECORD=0 npm run build && npm run test:unit && npm run test:integration && npm run test:e2e && npm run lint && npm run test:typescript-declaration",
"test:watch": "npm run test:unit -- --watch",
"test:unit": "NODE_ENV=test mocha --require test/setup-unit.js --recursive 'test/unit/**/**/*.spec.{js,ts}'",
"test:integration": "NODE_ENV=test mocha --require test/integration/setup.js 'test/integration/**/*.spec.js'",
"test:e2e": "NODE_ENV=test mocha 'test/end-to-end/**/*.spec.js'",
"test:typescript-declaration": "tsc --strict --noEmit index.d.ts",
"lint": "eslint 'examples/**/*.js' 'test/**/*.js' 'src/**/*.js' && tslint --project tsconfig-dev.json --config tslint.json -e '**/*.js'",
"semantic-release": "semantic-release",
"travis-deploy-once": "travis-deploy-once",
"test-unit-debug": "NODE_ENV=test mocha debug --require test/setup-unit.js --recursive 'test/unit/**/**/*.spec.{js,ts}'",
"test-integration-debug": "NODE_ENV=test mocha debug --require test/integration/setup.js 'test/integration/**/*.spec.js'",
"test-e2e-debug": "NODE_ENV=test mocha debug 'test/end-to-end/**/*.spec.js'",
"test:unit:debug": "NODE_ENV=test mocha debug --require test/setup-unit.js --recursive 'test/unit/**/**/*.spec.{js,ts}'",
"test:integration:debug": "NODE_ENV=test mocha debug --require test/integration/setup.js 'test/integration/**/*.spec.js'",
"test:e2e:debug": "NODE_ENV=test mocha debug 'test/end-to-end/**/*.spec.js'",
"cm": "git-cz"
},
"files": [
Expand Down
4 changes: 2 additions & 2 deletions test/end-to-end/cli-as-lib.js
Expand Up @@ -2,8 +2,8 @@

const nixt = require('nixt');

const SPACE_ID = process.env.CONTENTFUL_INTEGRATION_SOURCE_SPACE;
const ACCESS_TOKEN = process.env.CONTENTFUL_INTEGRATION_MANAGEMENT_TOKEN;
const SPACE_ID = process.env.CONTENTFUL_SPACE_ID;
const ACCESS_TOKEN = process.env.CONTENTFUL_INTEGRATION_TEST_CMA_TOKEN;
const cli = () => {
return nixt()
.env('CONTENTFUL_SPACE_ID', SPACE_ID)
Expand Down
2 changes: 1 addition & 1 deletion test/end-to-end/cli.js
Expand Up @@ -2,7 +2,7 @@

const nixt = require('nixt');

const ACCESS_TOKEN = process.env.CONTENTFUL_INTEGRATION_MANAGEMENT_TOKEN;
const ACCESS_TOKEN = process.env.CONTENTFUL_INTEGRATION_TEST_CMA_TOKEN;
process.env.TEST_ENVIRONMENT = 'end-to-end-tests';
const cli = () => {
return nixt()
Expand Down
2 changes: 1 addition & 1 deletion test/end-to-end/content-transform.spec.js
Expand Up @@ -5,7 +5,7 @@ const _ = require('lodash');
const assert = require('./assertions');
const cli = require('./cli');
const { createDevEnvironment, deleteDevEnvironment, getEntries, makeRequest } = require('../helpers/client');
const SOURCE_TEST_SPACE = process.env.CONTENTFUL_INTEGRATION_SOURCE_SPACE;
const SOURCE_TEST_SPACE = process.env.CONTENTFUL_SPACE_ID;

const uuid = require('uuid');
const ENVIRONMENT_ID = uuid.v4();
Expand Down
2 changes: 1 addition & 1 deletion test/end-to-end/content-type.spec.js
Expand Up @@ -11,7 +11,7 @@ const { createDevEnvironment, deleteDevEnvironment, getDevContentType, getDevTag
const uuid = require('uuid');
const ENVIRONMENT_ID = uuid.v4();

const SOURCE_TEST_SPACE = process.env.CONTENTFUL_INTEGRATION_SOURCE_SPACE;
const SOURCE_TEST_SPACE = process.env.CONTENTFUL_SPACE_ID;

describe('apply content-type migration examples', function () {
this.timeout(30000);
Expand Down
2 changes: 1 addition & 1 deletion test/end-to-end/derive-entry.spec.js
Expand Up @@ -9,7 +9,7 @@ const { createDevEnvironment, deleteDevEnvironment, getEntries, makeRequest } =
const uuid = require('uuid');
const ENVIRONMENT_ID = uuid.v4();

const SOURCE_TEST_SPACE = process.env.CONTENTFUL_INTEGRATION_SOURCE_SPACE;
const SOURCE_TEST_SPACE = process.env.CONTENTFUL_SPACE_ID;

describe('apply derive entry transformation', function () {
this.timeout(30000);
Expand Down
2 changes: 1 addition & 1 deletion test/end-to-end/editor-interface.spec.js
Expand Up @@ -11,7 +11,7 @@ const { createDevEnvironment, deleteDevEnvironment, getDevEditorInterface } = re
const uuid = require('uuid');
const ENVIRONMENT_ID = uuid.v4();

const SOURCE_TEST_SPACE = process.env.CONTENTFUL_INTEGRATION_SOURCE_SPACE;
const SOURCE_TEST_SPACE = process.env.CONTENTFUL_SPACE_ID;

describe('apply editor-interface migration examples', function () {
this.timeout(30000);
Expand Down
2 changes: 1 addition & 1 deletion test/end-to-end/entry-extensions.spec.js
Expand Up @@ -11,7 +11,7 @@ const {
const uuid = require('uuid');
const ENVIRONMENT_ID = uuid.v4();

const SOURCE_TEST_SPACE = process.env.CONTENTFUL_INTEGRATION_SOURCE_SPACE;
const SOURCE_TEST_SPACE = process.env.CONTENTFUL_SPACE_ID;

describe('apply entry extension migration examples', function () {
this.timeout(30000);
Expand Down
2 changes: 1 addition & 1 deletion test/end-to-end/entry-set-tags.spec.js
Expand Up @@ -9,7 +9,7 @@ const { createDevEnvironment, deleteDevEnvironment, makeRequest } = require('../
const uuid = require('uuid');
const ENVIRONMENT_ID = uuid.v4();

const SOURCE_TEST_SPACE = process.env.CONTENTFUL_INTEGRATION_SOURCE_SPACE;
const SOURCE_TEST_SPACE = process.env.CONTENTFUL_SPACE_ID;

describe('apply set tags transformation', function () {
this.timeout(30000);
Expand Down
2 changes: 1 addition & 1 deletion test/end-to-end/errors.spec.js
Expand Up @@ -3,7 +3,7 @@
const assert = require('./assertions');
const cli = require('./cli');

const SOURCE_TEST_SPACE = process.env.CONTENTFUL_INTEGRATION_SOURCE_SPACE;
const SOURCE_TEST_SPACE = process.env.CONTENTFUL_SPACE_ID;

describe('04-steps-errors.js', function () {
it('outputs the correct errors', function (done) {
Expand Down
2 changes: 1 addition & 1 deletion test/end-to-end/fields.spec.js
Expand Up @@ -11,7 +11,7 @@ const { createDevEnvironment, deleteDevEnvironment, getDevContentType } = requir
const uuid = require('uuid');
const ENVIRONMENT_ID = uuid.v4();

const SOURCE_TEST_SPACE = process.env.CONTENTFUL_INTEGRATION_SOURCE_SPACE;
const SOURCE_TEST_SPACE = process.env.CONTENTFUL_SPACE_ID;

describe('apply field migration examples', function () {
this.timeout(30000);
Expand Down
2 changes: 1 addition & 1 deletion test/end-to-end/flags.spec.js
Expand Up @@ -5,7 +5,7 @@ const path = require('path');
const assert = require('./assertions');
const cli = require('./cli');

const SOURCE_TEST_SPACE = process.env.CONTENTFUL_INTEGRATION_SOURCE_SPACE;
const SOURCE_TEST_SPACE = process.env.CONTENTFUL_SPACE_ID;

describe('contentful-migration CLI flags', function () {
it('"--help" outputs the help message', function (done) {
Expand Down
2 changes: 1 addition & 1 deletion test/end-to-end/payload.spec.js
Expand Up @@ -3,7 +3,7 @@
const assert = require('./assertions');
const cli = require('./cli');

const SOURCE_TEST_SPACE = process.env.CONTENTFUL_INTEGRATION_SOURCE_SPACE;
const SOURCE_TEST_SPACE = process.env.CONTENTFUL_SPACE_ID;

describe('invalid payload errors', function () {
it('outputs the validation errors', function (done) {
Expand Down
2 changes: 1 addition & 1 deletion test/end-to-end/sidebar.spec.js
Expand Up @@ -8,7 +8,7 @@ const { DEFAULT_SIDEBAR_LIST } = require('../../built/lib/action/sidebarwidget')
const uuid = require('uuid');
const ENVIRONMENT_ID = uuid.v4();

const SOURCE_TEST_SPACE = process.env.CONTENTFUL_INTEGRATION_SOURCE_SPACE;
const SOURCE_TEST_SPACE = process.env.CONTENTFUL_SPACE_ID;

describe('apply sidebar migration examples', function () {
this.timeout(30000);
Expand Down
2 changes: 1 addition & 1 deletion test/end-to-end/tag.spec.js
Expand Up @@ -8,7 +8,7 @@ const { createDevEnvironment, deleteDevEnvironment, getDevTag } = require('../he
const uuid = require('uuid');
const ENVIRONMENT_ID = uuid.v4();

const SOURCE_TEST_SPACE = process.env.CONTENTFUL_INTEGRATION_SOURCE_SPACE;
const SOURCE_TEST_SPACE = process.env.CONTENTFUL_SPACE_ID;

describe('apply tag migration examples', function () {
this.timeout(30000);
Expand Down
2 changes: 1 addition & 1 deletion test/end-to-end/validations.spec.js
Expand Up @@ -17,7 +17,7 @@ const {
const uuid = require('uuid');
const ENVIRONMENT_ID = uuid.v4();

const SOURCE_TEST_SPACE = process.env.CONTENTFUL_INTEGRATION_SOURCE_SPACE;
const SOURCE_TEST_SPACE = process.env.CONTENTFUL_SPACE_ID;

describe('apply validations migration examples', function () {
this.timeout(30000);
Expand Down
2 changes: 1 addition & 1 deletion test/helpers/client.js
Expand Up @@ -6,7 +6,7 @@ const { createManagementClient } = require('../../built/bin/lib/contentful-clien
const createMakeRequest = require('../../built/bin/cli').createMakeRequest;

const config = {
accessToken: process.env.CONTENTFUL_INTEGRATION_MANAGEMENT_TOKEN,
accessToken: process.env.CONTENTFUL_INTEGRATION_TEST_CMA_TOKEN,
application: `contentful.migration-cli.e2e-test/${packageVersion}`
};

Expand Down
7 changes: 4 additions & 3 deletions test/integration/bin/lib/contentful-client.spec.js
Expand Up @@ -11,10 +11,10 @@ const { createManagementClient } = contentfulClient;
// Ensure that when both tokens are defined, we first take the integration one
// This is mostly useful for local testing where both may be defined
delete process.env['CONTENTFUL_MANAGEMENT_ACCESS_TOKEN'];
const SOURCE_TEST_SPACE = process.env.CONTENTFUL_INTEGRATION_SOURCE_SPACE;
const SOURCE_TEST_SPACE = process.env.CONTENTFUL_SPACE_ID;

const fileConfig = {
cmaToken: process.env.CONTENTFUL_INTEGRATION_MANAGEMENT_TOKEN
cmaToken: process.env.CONTENTFUL_INTEGRATION_TEST_CMA_TOKEN
};

describe('contentful-client', function () {
Expand All @@ -23,12 +23,13 @@ describe('contentful-client', function () {
});

it('can read the space', function () {
const spaceName = 'contentful-migration';
const clientConfig = Object.assign({
application: `contentful.migration-cli/0.0.0`
}, getConfig());
const client = createManagementClient(clientConfig);
return client.space.get({ spaceId: SOURCE_TEST_SPACE }).then((space) => {
expect(space.name).to.eql('Migrations CLI Test');
expect(space.name).to.eql(spaceName);
});
});

Expand Down
2 changes: 1 addition & 1 deletion test/integration/migration.spec.js
Expand Up @@ -37,7 +37,7 @@ after(recorder.after);

const ENVIRONMENT_ID = 'env-integration';

const SOURCE_TEST_SPACE = process.env.CONTENTFUL_INTEGRATION_SOURCE_SPACE;
const SOURCE_TEST_SPACE = process.env.CONTENTFUL_SPACE_ID;

describe('the migration', function () {
this.timeout(30000);
Expand Down
4 changes: 2 additions & 2 deletions test/integration/setup.js
@@ -1,8 +1,8 @@
'use strict';

const requiredEnvVars = [
'CONTENTFUL_INTEGRATION_SOURCE_SPACE',
'CONTENTFUL_INTEGRATION_MANAGEMENT_TOKEN'
'CONTENTFUL_SPACE_ID',
'CONTENTFUL_INTEGRATION_TEST_CMA_TOKEN'
];

const undefinedEnvVar = (key) => typeof process.env[key] === 'undefined';
Expand Down
8 changes: 4 additions & 4 deletions test/unit/bin/lib/config.spec.ts
Expand Up @@ -4,7 +4,7 @@ import { expect } from 'chai'
import { getConfig } from '../../../../src/bin/lib/config'

const fileConfig = {
cmaToken: process.env.CONTENTFUL_INTEGRATION_MANAGEMENT_TOKEN
cmaToken: process.env.CONTENTFUL_INTEGRATION_TEST_CMA_TOKEN
}

describe('Config', function () {
Expand All @@ -14,16 +14,16 @@ describe('Config', function () {

it('reads the contentfulrc.json', async function () {
const config = getConfig({})
expect(config.accessToken).to.eql(process.env.CONTENTFUL_INTEGRATION_MANAGEMENT_TOKEN)
expect(config.accessToken).to.eql(process.env.CONTENTFUL_INTEGRATION_TEST_CMA_TOKEN)
})

it('prefers env config over contentfulrc.json', async function () {
const token = process.env.CONTENTFUL_INTEGRATION_MANAGEMENT_TOKEN
const token = process.env.CONTENTFUL_INTEGRATION_TEST_CMA_TOKEN

process.env.CONTENTFUL_MANAGEMENT_ACCESS_TOKEN = 'schnitzel'
const config = getConfig({})
expect(config.accessToken).to.eql('schnitzel')
process.env.CONTENTFUL_INTEGRATION_MANAGEMENT_TOKEN = token
process.env.CONTENTFUL_INTEGRATION_TEST_CMA_TOKEN = token
})

it('prefers handed in config over env config', async function () {
Expand Down

0 comments on commit 815d08b

Please sign in to comment.