
Security News
Axios Supply Chain Attack Reaches OpenAI macOS Signing Pipeline, Forces Certificate Rotation
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.
backstage-it
Advanced tools
Backstage-IT is an utility library designed to simplify the setup and teardown process for testing backend applications in the Backstage ecosystem. It provides convenient methods for initializing the server and database, making it easier to write integration tests.
To install Backstage-IT, you can use npm:
npm install backstage-it --save-dev
To use BackstageIt with Jest for testing your backend application, follow these steps to configure Jest:
npm install jest --save-dev
jest.config.js) in the root of your project with the following content:// jest.config.js
module.exports = {
// Other Jest configuration options...
rootDir: __dirname,
testEnvironment: 'node',
clearMocks: true,
setupFilesAfterEnv: [
'<rootDir>/tests/jest.setup.ts',
'<rootDir>/tests/jest.teardown.ts'
]
};
/tests folder, create the jest.setup.ts file for the test environment setup and jest.teardown.ts for teardown.// jest.setup.ts
import {resolvePackagePath} from "@backstage/backend-common";
import {startServer} from "../src";
import {request} from "pactum";
import {BackstageIt} from "backstage-it";
beforeAll(async () => {
await BackstageIt.setUp({
appName: 'my-service',
platformName: 'backstage',
logLevel: "debug",
database: {
databaseName: "my-service-db",
migrationsDir: resolvePackagePath(
'@my-company/my-service-plugin',
'migrations',
)
},
server: async (options) => {
// Do additional configuration or dependency resolution here as needed
// For example: instantiate services that your server needs other than the defaults coming within options
return await startServer(options);
},
afterSetup: async ({address, logger}) => {
// Additional setup logic after the server is started
logger.info(`Test Server running at ${address}`);
}
});
});
and the Teardown script:
// jest.teardown.ts
import {BackstageIt} from "backstage-it";
afterAll(async () => {
await BackstageIt.destroy();
});
describe('Server Integration Tests', () => {
it('should handle GET requests to /api/endpoint', async () => {
// Create a repository that uses the databse through Knex
const repository = new SampleRepository(BackstageIt.database);
// Call the repository to create and persist a new entity
const entity = await repository.create(CONTENT);
// Call the REST API to retrieve the create entity by using the generated ID
const response = await spec()
.get(`/api/endpoint/${entity.id!}`)
.expectStatus(200)
.returns<Promise<SampleEntity>>("res.body");
// Asset to make sure the API returned the same item that was created in the database
expect(response).toBeDefined();
expect(response.id).toBe(entity.id);
})
});
You are free to use the library that best fits your needs. Just in case you want to use it with PactumJs, you just need to configure Pactum in the initialization callback:
// jest.setup.ts
import {resolvePackagePath} from "@backstage/backend-common";
import {startServer} from "../src";
import {request} from "pactum";
import {BackstageIt} from "backstage-it";
beforeAll(async () => {
await BackstageIt.setUp({
...
afterSetup: async ({address, logger}) => {
// Additional setup logic after the server is started
logger.info(`Test Server running at ${address}`);
// Pre-configure PactumJs: Sets the server address for Pactum framework
request.setBaseUrl(address);
}
});
});
Then you can do API Tests without specifying the server address:
...
// Call the REST API to retrieve the create entity by using the generated ID
const response = await spec()
.get(`/api/endpoint/${entity.id!}`)
.expectStatus(200)
.returns<Promise<SampleEntity>>("res.body");
...
If you want to test the persistence layer only, there is no need to start the serve, in such case, you can skip the start server configuration.
await BackstageIt.setUp({
appName: 'academy-server',
platformName: 'backstage',
logLevel: 'debug',
database: {
databaseName: 'academy',
migrationsDir: resolvePackagePath(
'@mercedes-benz/academy-server',
'migrations',
),
}
});
BackstageIt.setUp(config: TestServerConfig) Initializes the server and database for the application. Accepts a configuration
object with the following properties:
BackstageIt.destroy() Shuts down the server and destroys the database connection.
BackstageIt.serverAddress(): string Returns the address of the server.
BackstageIt.serverPort(): number Returns the port number of the server.
The integration tests should be able to run the same start server script that your application uses in order to keep things paired and make sure tests are bootstrapping the real application.
Something similar to the following:
export async function startServer(options: ServerOptions): Promise<Server> {
const logger = options.logger.child({plugin: PLUGIN_ID});
logger.info('Loading configurations ...');
const config = options.optionalConfig ?? await loadBackendConfig({
argv: process.argv,
logger,
});
const environment = await createEnv(config, logger, options.optionalDatabase);
logger.info('Registering API...');
const router = await createRouter(environment);
const service = createServiceBuilder(module)
.enableCors({origin: '*'})
.setRequestLoggingHandler(createRequestLogger)
.addRouter('', await createHealthRouter())
.addRouter('/my-api', router);
logger.info('Starting Server...');
return service
.setPort(options.port)
.start()
.catch(err => {
logger.error(err);
process.exit(1);
});
}
FAQs
Integration tests Setup for Backstage backend services
The npm package backstage-it receives a total of 0 weekly downloads. As such, backstage-it popularity was classified as not popular.
We found that backstage-it demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.

Security News
Open source is under attack because of how much value it creates. It has been the foundation of every major software innovation for the last three decades. This is not the time to walk away from it.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.