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 3, 2024
1 parent d814858 commit 9ffe26f
Show file tree
Hide file tree
Showing 30 changed files with 2,733 additions and 5,408 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
test-utils:
strategy:
matrix:
node-version: [18.20.0, 20.12.0]
node-version: [20.12.0]
runs-on: ubuntu-22.04
steps:
- run: sudo apt update && sudo apt install ansible
Expand Down Expand Up @@ -60,10 +60,10 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 18.20.0
node-version: 20.12.0
cache: yarn
- run: yarn install --frozen-lockfile
- run: yarn test:generators --shard=${{ matrix.shard }}
- run: node --test --test-shard=${{ matrix.shard }} --loader ts-node/esm --experimental-specifier-resolution=node

test-update-script:
runs-on: ubuntu-22.04
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.vite).toBeDefined();
assert.ok(config.devDependencies.vite);
});

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).toBeUndefined();
expect(all.services[packageName]).toBeDefined();
assert(!('version' in all));
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 9ffe26f

Please sign in to comment.