Skip to content

Commit

Permalink
refactor: use sandbox.path instead of SANDBOX to access the sandbox d…
Browse files Browse the repository at this point in the history
…irectory

The starting path for a sandbox is not necessarily the target directory as
we may create a unique subdir under the path to ensure sandboxes can be used
in parallel testing.
  • Loading branch information
raymondfeng committed Apr 2, 2020
1 parent 29e2076 commit 9ea5243
Show file tree
Hide file tree
Showing 37 changed files with 414 additions and 451 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ export interface AppWithClient {
client: Client;
}

const SANDBOX = path.resolve(__dirname, '../../../.sandbox');
export function getSandbox() {
const sandbox = new TestSandbox(SANDBOX);
const sandbox = new TestSandbox(path.resolve(__dirname, '../../../.sandbox'));
return sandbox;
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ import {BooterApp} from '../fixtures/application';

describe('application metadata booter acceptance tests', () => {
let app: BooterApp;
const SANDBOX_PATH = resolve(__dirname, '../../.sandbox');
const sandbox = new TestSandbox(SANDBOX_PATH);
const sandbox = new TestSandbox(resolve(__dirname, '../../.sandbox'));

beforeEach('reset sandbox', () => sandbox.reset());
beforeEach(getApp);
Expand All @@ -36,7 +35,7 @@ describe('application metadata booter acceptance tests', () => {
'dist/application.js',
);

const MyApp = require(resolve(SANDBOX_PATH, 'dist/application.js'))
const MyApp = require(resolve(sandbox.path, 'dist/application.js'))
.BooterApp;
app = new MyApp({
rest: givenHttpServerConfig(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ import {BooterApp} from '../fixtures/application';

describe('controller booter acceptance tests', () => {
let app: BooterApp;
const SANDBOX_PATH = resolve(__dirname, '../../.sandbox');
const sandbox = new TestSandbox(SANDBOX_PATH);
const sandbox = new TestSandbox(resolve(__dirname, '../../.sandbox'));

beforeEach('reset sandbox', () => sandbox.reset());
beforeEach(getApp);
Expand All @@ -40,7 +39,7 @@ describe('controller booter acceptance tests', () => {
'controllers/multiple.controller.js',
);

const MyApp = require(resolve(SANDBOX_PATH, 'application.js')).BooterApp;
const MyApp = require(resolve(sandbox.path, 'application.js')).BooterApp;
app = new MyApp({
rest: givenHttpServerConfig(),
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ import {ProductRepository} from '../fixtures/product.repository';

describe('CRUD rest builder acceptance tests', () => {
let app: BooterApp;
const SANDBOX_PATH = resolve(__dirname, '../../.sandbox');
const sandbox = new TestSandbox(SANDBOX_PATH);
const sandbox = new TestSandbox(resolve(__dirname, '../../.sandbox'));

beforeEach('reset sandbox', () => sandbox.reset());
beforeEach(givenAppWithDataSource);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ import {

describe('model API booter acceptance tests', () => {
let app: BooterApp;
const SANDBOX_PATH = resolve(__dirname, '../../.sandbox');
const sandbox = new TestSandbox(SANDBOX_PATH);
const sandbox = new TestSandbox(resolve(__dirname, '../../.sandbox'));

beforeEach('reset sandbox', () => sandbox.reset());
beforeEach(givenAppWithDataSource);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import {resolve} from 'path';
import {BooterApp} from '../fixtures/application';

describe('controller booter integration tests', () => {
const SANDBOX_PATH = resolve(__dirname, '../../.sandbox');
const sandbox = new TestSandbox(SANDBOX_PATH);
const sandbox = new TestSandbox(resolve(__dirname, '../../.sandbox'));

// Remnants from Refactor -- need to add these to core
const CONTROLLERS_PREFIX = 'controllers';
Expand Down Expand Up @@ -39,7 +38,7 @@ describe('controller booter integration tests', () => {
'controllers/multiple.controller.js',
);

const MyApp = require(resolve(SANDBOX_PATH, 'application.js')).BooterApp;
const MyApp = require(resolve(sandbox.path, 'application.js')).BooterApp;
app = new MyApp();
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import {resolve} from 'path';
import {BooterApp} from '../fixtures/application';

describe('datasource booter integration tests', () => {
const SANDBOX_PATH = resolve(__dirname, '../../.sandbox');
const sandbox = new TestSandbox(SANDBOX_PATH);
const sandbox = new TestSandbox(resolve(__dirname, '../../.sandbox'));

const DATASOURCES_PREFIX = 'datasources';
const DATASOURCES_TAG = 'datasource';
Expand All @@ -35,7 +34,7 @@ describe('datasource booter integration tests', () => {
'datasources/db.datasource.js',
);

const MyApp = require(resolve(SANDBOX_PATH, 'application.js')).BooterApp;
const MyApp = require(resolve(sandbox.path, 'application.js')).BooterApp;
app = new MyApp();
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ import {resolve} from 'path';
import {BooterApp} from '../fixtures/application';

describe('interceptor script booter integration tests', () => {
const SANDBOX_PATH = resolve(__dirname, '../../.sandbox');
const sandbox = new TestSandbox(SANDBOX_PATH);
const sandbox = new TestSandbox(resolve(__dirname, '../../.sandbox'));

let app: BooterApp;

Expand Down Expand Up @@ -76,7 +75,7 @@ describe('interceptor script booter integration tests', () => {
'interceptors/non-global-interceptor.interceptor.js',
);

const MyApp = require(resolve(SANDBOX_PATH, 'application.js')).BooterApp;
const MyApp = require(resolve(sandbox.path, 'application.js')).BooterApp;
app = new MyApp();
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ import {resolve} from 'path';
import {BooterApp} from '../fixtures/application';

describe('lifecycle script booter integration tests', () => {
const SANDBOX_PATH = resolve(__dirname, '../../.sandbox');
const sandbox = new TestSandbox(SANDBOX_PATH);
const sandbox = new TestSandbox(resolve(__dirname, '../../.sandbox'));

const OBSERVER_PREFIX = CoreBindings.LIFE_CYCLE_OBSERVERS;
const OBSERVER_TAG = CoreTags.LIFE_CYCLE_OBSERVER;
Expand Down Expand Up @@ -47,7 +46,7 @@ describe('lifecycle script booter integration tests', () => {
'observers/lifecycle-observer.observer.js',
);

const MyApp = require(resolve(SANDBOX_PATH, 'application.js')).BooterApp;
const MyApp = require(resolve(sandbox.path, 'application.js')).BooterApp;
app = new MyApp();
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import {resolve} from 'path';
import {BooterApp} from '../fixtures/application';

describe('repository booter integration tests', () => {
const SANDBOX_PATH = resolve(__dirname, '../../.sandbox');
const sandbox = new TestSandbox(SANDBOX_PATH);
const sandbox = new TestSandbox(resolve(__dirname, '../../.sandbox'));

// Remnants from Refactor -- need to add these to core
const REPOSITORIES_PREFIX = 'repositories';
Expand Down Expand Up @@ -39,7 +38,7 @@ describe('repository booter integration tests', () => {
'repositories/multiple.repository.js',
);

const MyApp = require(resolve(SANDBOX_PATH, 'application.js')).BooterApp;
const MyApp = require(resolve(sandbox.path, 'application.js')).BooterApp;
app = new MyApp();
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import {resolve} from 'path';
import {BooterApp} from '../fixtures/application';

describe('service booter integration tests', () => {
const SANDBOX_PATH = resolve(__dirname, '../../.sandbox');
const sandbox = new TestSandbox(SANDBOX_PATH);
const sandbox = new TestSandbox(resolve(__dirname, '../../.sandbox'));

const SERVICES_PREFIX = 'services';
const SERVICES_TAG = 'service';
Expand Down Expand Up @@ -62,7 +61,7 @@ describe('service booter integration tests', () => {
'services/bindable-classes.service.js',
);

const MyApp = require(resolve(SANDBOX_PATH, 'application.js')).BooterApp;
const MyApp = require(resolve(sandbox.path, 'application.js')).BooterApp;
app = new MyApp();
}
});
21 changes: 10 additions & 11 deletions packages/boot/src/__tests__/unit/booters/booter-utils.unit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import {resolve} from 'path';
import {discoverFiles, isClass, loadClassesFromFiles} from '../../..';

describe('booter-utils unit tests', () => {
const SANDBOX_PATH = resolve(__dirname, '../../../.sandbox');
const sandbox = new TestSandbox(SANDBOX_PATH);
const sandbox = new TestSandbox(resolve(__dirname, '../../../.sandbox'));

beforeEach('reset sandbox', () => sandbox.reset());

Expand All @@ -18,26 +17,26 @@ describe('booter-utils unit tests', () => {

it('discovers files matching a nested glob pattern', async () => {
const expected = [
resolve(SANDBOX_PATH, 'empty.artifact.js'),
resolve(SANDBOX_PATH, 'nested/multiple.artifact.js'),
resolve(sandbox.path, 'empty.artifact.js'),
resolve(sandbox.path, 'nested/multiple.artifact.js'),
];
const glob = '/**/*.artifact.js';

const files = await discoverFiles(glob, SANDBOX_PATH);
const files = await discoverFiles(glob, sandbox.path);
expect(files.sort()).to.eql(expected.sort());
});

it('discovers files matching a non-nested glob pattern', async () => {
const expected = [resolve(SANDBOX_PATH, 'empty.artifact.js')];
const expected = [resolve(sandbox.path, 'empty.artifact.js')];
const glob = '/*.artifact.js';

const files = await discoverFiles(glob, SANDBOX_PATH);
const files = await discoverFiles(glob, sandbox.path);
expect(files).to.eql(expected);
});

it('discovers no files for a unknown glob', async () => {
const glob = '/xyz';
const files = await discoverFiles(glob, SANDBOX_PATH);
const files = await discoverFiles(glob, sandbox.path);
expect(files).to.be.eql([]);
});

Expand All @@ -64,7 +63,7 @@ describe('booter-utils unit tests', () => {
await sandbox.copyFile(
resolve(__dirname, '../../fixtures/multiple.artifact.js'),
);
const files = [resolve(SANDBOX_PATH, 'multiple.artifact.js')];
const files = [resolve(sandbox.path, 'multiple.artifact.js')];
const NUM_CLASSES = 2; // Number of classes in above file

const classes = loadClassesFromFiles(files, sandbox.path);
Expand All @@ -77,15 +76,15 @@ describe('booter-utils unit tests', () => {
await sandbox.copyFile(
resolve(__dirname, '../../fixtures/empty.artifact.js'),
);
const files = [resolve(SANDBOX_PATH, 'empty.artifact.js')];
const files = [resolve(sandbox.path, 'empty.artifact.js')];

const classes = loadClassesFromFiles(files, sandbox.path);
expect(classes).to.be.an.Array();
expect(classes).to.be.empty();
});

it('throws an error given a non-existent file', async () => {
const files = [resolve(SANDBOX_PATH, 'fake.artifact.js')];
const files = [resolve(sandbox.path, 'fake.artifact.js')];
expect(() => loadClassesFromFiles(files, sandbox.path)).to.throw(
/Cannot find module/,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ import {resolve} from 'path';
import {ControllerBooter, ControllerDefaults} from '../../..';

describe('controller booter unit tests', () => {
const SANDBOX_PATH = resolve(__dirname, '../../../.sandbox');
const sandbox = new TestSandbox(SANDBOX_PATH);
const sandbox = new TestSandbox(resolve(__dirname, '../../../.sandbox'));

const CONTROLLERS_PREFIX = 'controllers';
const CONTROLLERS_TAG = 'controller';
Expand All @@ -21,7 +20,7 @@ describe('controller booter unit tests', () => {
beforeEach(getApp);

it(`constructor uses ControllerDefaults for 'options' if none are given`, () => {
const booterInst = new ControllerBooter(app, SANDBOX_PATH);
const booterInst = new ControllerBooter(app, sandbox.path);
expect(booterInst.options).to.deepEqual(ControllerDefaults);
});

Expand All @@ -34,7 +33,7 @@ describe('controller booter unit tests', () => {
nested: ControllerDefaults.nested,
});

const booterInst = new ControllerBooter(app, SANDBOX_PATH, options);
const booterInst = new ControllerBooter(app, sandbox.path, options);
expect(booterInst.options).to.deepEqual(expected);
});

Expand All @@ -46,11 +45,11 @@ describe('controller booter unit tests', () => {
await sandbox.copyFile(
resolve(__dirname, '../../fixtures/multiple.artifact.js'),
);
const booterInst = new ControllerBooter(app, SANDBOX_PATH);
const booterInst = new ControllerBooter(app, sandbox.path);
const NUM_CLASSES = 2; // 2 classes in above file.

// Load uses discovered property
booterInst.discovered = [resolve(SANDBOX_PATH, 'multiple.artifact.js')];
booterInst.discovered = [resolve(sandbox.path, 'multiple.artifact.js')];
await booterInst.load();

const ctrls = app.findByTag(CONTROLLERS_TAG);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ import {resolve} from 'path';
import {DataSourceBooter, DataSourceDefaults} from '../../..';

describe('datasource booter unit tests', () => {
const SANDBOX_PATH = resolve(__dirname, '../../../.sandbox');
const sandbox = new TestSandbox(SANDBOX_PATH);
const sandbox = new TestSandbox(resolve(__dirname, '../../../.sandbox'));

const DATASOURCES_PREFIX = 'datasources';
const DATASOURCES_TAG = 'datasource';
Expand All @@ -38,10 +37,10 @@ describe('datasource booter unit tests', () => {

const booterInst = new DataSourceBooter(
normalApp as ApplicationWithRepositories,
SANDBOX_PATH,
sandbox.path,
);

booterInst.discovered = [resolve(SANDBOX_PATH, 'datasource.artifact.js')];
booterInst.discovered = [resolve(sandbox.path, 'datasource.artifact.js')];
await booterInst.load();

sinon.assert.calledOnce(stub);
Expand All @@ -53,7 +52,7 @@ describe('datasource booter unit tests', () => {
});

it(`uses DataSourceDefaults for 'options' if none are given`, () => {
const booterInst = new DataSourceBooter(app, SANDBOX_PATH);
const booterInst = new DataSourceBooter(app, sandbox.path);
expect(booterInst.options).to.deepEqual(DataSourceDefaults);
});

Expand All @@ -66,7 +65,7 @@ describe('datasource booter unit tests', () => {
nested: DataSourceDefaults.nested,
});

const booterInst = new DataSourceBooter(app, SANDBOX_PATH, options);
const booterInst = new DataSourceBooter(app, sandbox.path, options);
expect(booterInst.options).to.deepEqual(expected);
});

Expand All @@ -75,10 +74,10 @@ describe('datasource booter unit tests', () => {
await sandbox.copyFile(
resolve(__dirname, '../../fixtures/datasource.artifact.js'),
);
const booterInst = new DataSourceBooter(app, SANDBOX_PATH);
const booterInst = new DataSourceBooter(app, sandbox.path);
const NUM_CLASSES = 1; // 1 class in above file.

booterInst.discovered = [resolve(SANDBOX_PATH, 'datasource.artifact.js')];
booterInst.discovered = [resolve(sandbox.path, 'datasource.artifact.js')];
await booterInst.load();

const datasources = app.findByTag(DATASOURCES_TAG);
Expand Down
Loading

0 comments on commit 9ea5243

Please sign in to comment.