Skip to content

Commit

Permalink
Run tests using node instead of jest
Browse files Browse the repository at this point in the history
  • Loading branch information
jvasseur committed Apr 27, 2023
1 parent b9fa70e commit e451464
Show file tree
Hide file tree
Showing 28 changed files with 429 additions and 2,198 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 14.21.2
node-version: 16.19.0
cache: yarn
- run: yarn install --frozen-lockfile
- run: yarn lint
Expand All @@ -24,15 +24,15 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 14.21.2
node-version: 16.19.0
cache: yarn
- run: yarn install --frozen-lockfile
- run: yarn build

test-utils:
strategy:
matrix:
node-version: [14.21.2, 16.19.0, 18.13.0]
node-version: [16.19.0, 18.16.0]
runs-on: ubuntu-20.04
steps:
- run: sudo apt update && sudo apt install ansible
Expand Down Expand Up @@ -60,7 +60,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 14.21.2
node-version: 16.19.0
cache: yarn
- run: yarn install --frozen-lockfile
- run: yarn test:generators --shard=${{ matrix.shard }}
Expand Down
62 changes: 32 additions & 30 deletions generators/app/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import fs from 'fs';
import path from 'path';
import { strict as assert } from 'node:assert';
import fs from 'node:fs';
import path from 'node:path';
import { after, before, describe, test } from 'node:test';
import YAML from 'yaml';
import helpers from 'yeoman-test';
import * as CircleCI from '../../utils/circleci';

describe('When running the generator with React', () => {
let root: string;

beforeAll(async () => {
before(async () => {
const result = await helpers.run(__dirname)
.withPrompts({
backend: 'express',
Expand All @@ -18,27 +20,27 @@ describe('When running the generator with React', () => {
root = result.cwd;
});

afterAll(async () => {
after(async () => {
await fs.promises.rm(root, { recursive: true });
});

test('It generates an Express backend', async () => {
const config = JSON.parse(await fs.promises.readFile(path.resolve(root, 'backend', 'package.json'), 'utf8'));

expect(config.dependencies.express).toBeDefined();
assert.ok(config.dependencies.express);
});

test('It generates a React frontend', async () => {
const config = JSON.parse(await fs.promises.readFile(path.resolve(root, 'frontend', 'package.json'), 'utf8'));

expect(config.devDependencies['react-scripts']).toBeDefined();
assert.ok(config.devDependencies['react-scripts']);
});

test('It add the right dependencies to the deploy job', async () => {
test('It adds the right dependencies to the deploy job', async () => {
const content = await fs.promises.readFile(path.resolve(root, '.circleci', 'config.yml'), 'utf8');
const config = CircleCI.Config.fromRaw(YAML.parse(content));

expect(config.workflows.build?.jobs.deploy?.requires).toEqual([
assert.deepEqual(config.workflows.build?.jobs.deploy?.requires, [
'backend-archive',
'frontend-archive',
]);
Expand All @@ -48,7 +50,7 @@ describe('When running the generator with React', () => {
describe('When running the generator with Next.js', () => {
let root: string;

beforeAll(async () => {
before(async () => {
const result = await helpers.run(__dirname)
.withPrompts({
backend: 'express',
Expand All @@ -59,27 +61,27 @@ describe('When running the generator with Next.js', () => {
root = result.cwd;
});

afterAll(async () => {
after(async () => {
await fs.promises.rm(root, { recursive: true });
});

test('It generates an Express backend', async () => {
const config = JSON.parse(await fs.promises.readFile(path.resolve(root, 'backend', 'package.json'), 'utf8'));

expect(config.dependencies.express).toBeDefined();
assert.ok(config.dependencies.express);
});

test('It generates an Next.js frontend', async () => {
const config = JSON.parse(await fs.promises.readFile(path.resolve(root, 'frontend', 'package.json'), 'utf8'));

expect(config.dependencies.next).toBeDefined();
assert.ok(config.dependencies.next);
});

test('It add the right dependencies to the deploy job', async () => {
test('It adds the right dependencies to the deploy job', async () => {
const content = await fs.promises.readFile(path.resolve(root, '.circleci', 'config.yml'), 'utf8');
const config = CircleCI.Config.fromRaw(YAML.parse(content));

expect(config.workflows.build?.jobs.deploy?.requires).toEqual([
assert.deepEqual(config.workflows.build?.jobs.deploy?.requires, [
'backend-archive',
'frontend-archive',
]);
Expand All @@ -89,7 +91,7 @@ describe('When running the generator with Next.js', () => {
describe('When running the generator with Symfony', () => {
let root: string;

beforeAll(async () => {
before(async () => {
const result = await helpers.run(__dirname)
.withPrompts({
backend: 'symfony',
Expand All @@ -101,15 +103,15 @@ describe('When running the generator with Symfony', () => {
root = result.cwd;
});

afterAll(async () => {
after(async () => {
await fs.promises.rm(root, { recursive: true });
});

test('It add the right dependencies to the deploy job', async () => {
test('It adds the right dependencies to the deploy job', async () => {
const content = await fs.promises.readFile(path.resolve(root, '.circleci', 'config.yml'), 'utf8');
const config = CircleCI.Config.fromRaw(YAML.parse(content));

expect(config.workflows.build?.jobs.deploy?.requires).toEqual([
assert.deepEqual(config.workflows.build?.jobs.deploy?.requires, [
'backend-build',
]);
});
Expand All @@ -118,7 +120,7 @@ describe('When running the generator with Symfony', () => {
describe('When running the generator with Flutter', () => {
let root: string;

beforeAll(async () => {
before(async () => {
const result = await helpers.run(__dirname)
.withPrompts({
projectName: 'my_project',
Expand All @@ -132,11 +134,11 @@ describe('When running the generator with Flutter', () => {
root = result.cwd;
});

afterAll(async () => {
after(async () => {
await fs.promises.rm(root, { recursive: true });
});

it('It generates a Flutter mobile app', async () => {
test('It generates a Flutter mobile app', async () => {
const config = YAML.parse(await fs.promises.readFile(
path.resolve(
root,
Expand All @@ -146,14 +148,14 @@ describe('When running the generator with Flutter', () => {
'utf8',
));

expect(config).toBeDefined();
assert.ok(config);
});
});

describe('When running the generator with React-Native', () => {
let root: string;

beforeAll(async () => {
before(async () => {
const result = await helpers.run(__dirname)
.withPrompts({
projectName: 'my_project',
Expand All @@ -167,11 +169,11 @@ describe('When running the generator with React-Native', () => {
root = result.cwd;
});

afterAll(async () => {
after(async () => {
await fs.promises.rm(root, { recursive: true });
});

it('It generates a React-Native mobile app', async () => {
test('It generates a React-Native mobile app', async () => {
const config = YAML.parse(await fs.promises.readFile(
path.resolve(
root,
Expand All @@ -181,14 +183,14 @@ describe('When running the generator with React-Native', () => {
'utf8',
));

expect(config).toBeDefined();
assert.ok(config);
});
});

describe('When running the generator without a Backend', () => {
let root: string;

beforeAll(async () => {
before(async () => {
const result = await helpers.run(__dirname)
.withPrompts({
backend: null,
Expand All @@ -199,11 +201,11 @@ describe('When running the generator without a Backend', () => {
root = result.cwd;
});

afterAll(async () => {
after(async () => {
await fs.promises.rm(root, { recursive: true });
});

it('It doesn\'t create a backend directory', async () => {
expect(fs.existsSync(path.resolve(root, 'backend'))).toBe(false);
test('It doesn\'t create a backend directory', async () => {
assert.ok(!fs.existsSync(path.resolve(root, 'backend')));
});
});
28 changes: 15 additions & 13 deletions generators/express/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import fs from 'fs';
import path from 'path';
import { strict as assert } from 'node:assert';
import fs from 'node:fs';
import path from 'node:path';
import { after, before, describe, test } from 'node:test';
import execa from 'execa';
import YAML from 'yaml';
import helpers from 'yeoman-test';
Expand All @@ -9,7 +11,7 @@ describe('When running the generator', () => {
let root: string;
const packageName = 'test';

beforeAll(async () => {
before(async () => {
const result = await helpers.run(path.resolve(__dirname, '../root'))
.withPrompts({ contactEmail: 'test@example.com' });

Expand All @@ -22,7 +24,7 @@ describe('When running the generator', () => {
await execa(path.resolve(root, 'script', 'bootstrap'));
});

afterAll(async () => {
after(async () => {
await execa('docker-compose', ['down', '--rmi', 'local', '--volumes'], { cwd: root });
await fs.promises.rm(root, { recursive: true });
});
Expand All @@ -45,20 +47,20 @@ describe('When running the generator', () => {

test('It generates a docker-compose.yaml with the right fields', async () => {
const all = YAML.parse(await fs.promises.readFile(path.resolve(root, 'docker-compose.yaml'), 'utf8'));
expect(all.version).toBeDefined();
expect(all.services[packageName]).toBeDefined();
assert.ok(all.version);
assert.ok(all.services[packageName]);
});

test('It extends the ansible configuration', async () => {
const all = YAML.parse(await fs.promises.readFile(path.resolve(root, 'ansible/group_vars/all.yaml'), 'utf8'));

expect(all.test_env).toBeDefined();
assert.ok(all.test_env);
});

test('The database is correctly added to production config', async () => {
const content = await fs.promises.readFile(path.resolve(root, 'terraform/common/database/main.tf'), 'utf8');

expect(content).toContain('resource "scaleway_rdb_database" "test" {');
assert.ok(content.includes('resource "scaleway_rdb_database" "test" {'));
});

test('It generates a project with a valid terraform config', async () => {
Expand All @@ -75,7 +77,7 @@ describe('When running the generator', () => {
describe('When running the generator with kubernetes deployment', () => {
let root: string;

beforeAll(async () => {
before(async () => {
const result = await helpers.run(path.resolve(__dirname, '../root'))
.withPrompts({ deployment: 'kubernetes' });

Expand All @@ -86,7 +88,7 @@ describe('When running the generator with kubernetes deployment', () => {
.withArguments(['test']);
});

afterAll(async () => {
after(async () => {
await fs.promises.rm(root, { recursive: true });
});

Expand Down Expand Up @@ -117,7 +119,7 @@ describe('When running the generator with kubernetes deployment', () => {
describe('When running the generator with the path option', () => {
let root: string;

beforeAll(async () => {
before(async () => {
const result = await helpers.run(path.resolve(__dirname, '../root'))
.withPrompts({ contactEmail: 'test@example.com' });

Expand All @@ -128,11 +130,11 @@ describe('When running the generator with the path option', () => {
.withArguments(['test', '--path', 'packages/test']);
});

afterAll(async () => {
after(async () => {
await fs.promises.rm(root, { recursive: true });
});

test('It generates the project in the given directory', async () => {
expect(fs.existsSync(path.join(root, 'packages/test'))).toBe(true);
assert.ok(fs.existsSync(path.join(root, 'packages/test')));
});
});
Loading

0 comments on commit e451464

Please sign in to comment.