Skip to content

Commit

Permalink
chore: move tests to node (#10111)
Browse files Browse the repository at this point in the history
  • Loading branch information
ematipico authored Feb 14, 2024
1 parent 50da330 commit 8c14143
Show file tree
Hide file tree
Showing 14 changed files with 586 additions and 559 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { expect } from 'chai';
import assert from 'node:assert/strict';
import { describe, before, it } from 'node:test';
import { loadFixture } from './test-utils.js';

const authorIds = ['Ben Holmes', 'Fred K Schott', 'Nate Moore'];
Expand All @@ -19,21 +20,21 @@ describe('Content Collections - data collections', () => {
});

it('Returns', async () => {
expect(Array.isArray(json)).to.be.true;
expect(json.length).to.equal(3);
assert.equal(Array.isArray(json), true);
assert.equal(json.length, 3);
});

it('Generates correct ids', async () => {
const ids = json.map((item) => item.id).sort();
expect(ids).to.deep.equal(['Ben Holmes', 'Fred K Schott', 'Nate Moore']);
assert.deepEqual(ids, ['Ben Holmes', 'Fred K Schott', 'Nate Moore']);
});

it('Generates correct data', async () => {
const names = json.map((item) => item.data.name);
expect(names).to.deep.equal(['Ben J Holmes', 'Fred K Schott', 'Nate Something Moore']);
assert.deepEqual(names, ['Ben J Holmes', 'Fred K Schott', 'Nate Something Moore']);

const twitterUrls = json.map((item) => item.data.twitter);
expect(twitterUrls).to.deep.equal([
assert.deepEqual(twitterUrls, [
'https://twitter.com/bholmesdev',
'https://twitter.com/FredKSchott',
'https://twitter.com/n_moore',
Expand All @@ -48,7 +49,7 @@ describe('Content Collections - data collections', () => {
json = JSON.parse(rawJson);
});
it('Grabs the item by the base file name', () => {
expect(json.id).to.equal('en');
assert.equal(json.id, 'en');
});
});

Expand All @@ -61,27 +62,27 @@ describe('Content Collections - data collections', () => {
});

it(`Returns ${authorId}`, async () => {
expect(json).to.haveOwnProperty('id');
expect(json.id).to.equal(authorId);
assert.equal(json.hasOwnProperty('id'), true);
assert.equal(json.id, authorId);
});

it(`Generates correct data for ${authorId}`, async () => {
expect(json).to.haveOwnProperty('data');
expect(json.data).to.haveOwnProperty('name');
expect(json.data).to.haveOwnProperty('twitter');
assert.equal(json.hasOwnProperty('data'), true);
assert.equal(json.data.hasOwnProperty('name'), true);
assert.equal(json.data.hasOwnProperty('twitter'), true);

switch (authorId) {
case 'Ben Holmes':
expect(json.data.name).to.equal('Ben J Holmes');
expect(json.data.twitter).to.equal('https://twitter.com/bholmesdev');
assert.equal(json.data.name, 'Ben J Holmes');
assert.equal(json.data.twitter, 'https://twitter.com/bholmesdev');
break;
case 'Fred K Schott':
expect(json.data.name).to.equal('Fred K Schott');
expect(json.data.twitter).to.equal('https://twitter.com/FredKSchott');
assert.equal(json.data.name, 'Fred K Schott');
assert.equal(json.data.twitter, 'https://twitter.com/FredKSchott');
break;
case 'Nate Moore':
expect(json.data.name).to.equal('Nate Something Moore');
expect(json.data.twitter).to.equal('https://twitter.com/n_moore');
assert.equal(json.data.name, 'Nate Something Moore');
assert.equal(json.data.twitter, 'https://twitter.com/n_moore');
break;
}
});
Expand All @@ -96,26 +97,22 @@ describe('Content Collections - data collections', () => {
});

it('Returns', async () => {
expect(Array.isArray(json)).to.be.true;
expect(json.length).to.equal(3);
assert.equal(Array.isArray(json), true);
assert.equal(json.length, 3);
});

it('Generates correct ids', async () => {
const ids = json.map((item) => item.id).sort();
expect(ids).to.deep.equal(translationIds);
assert.deepEqual(ids, translationIds);
});

it('Generates correct data', async () => {
const sorted = json.sort((a, b) => a.id.localeCompare(b.id));
const homepageGreetings = sorted.map((item) => item.data.homepage?.greeting);
expect(homepageGreetings).to.deep.equal([
'Hello World!',
'¡Hola Mundo!',
'Bonjour le monde!',
]);
assert.deepEqual(homepageGreetings, ['Hello World!', '¡Hola Mundo!', 'Bonjour le monde!']);

const homepagePreambles = sorted.map((item) => item.data.homepage?.preamble);
expect(homepagePreambles).to.deep.equal([
assert.deepEqual(homepagePreambles, [
'Welcome to the future of content.',
'Bienvenido al futuro del contenido.',
'Bienvenue dans le futur du contenu.',
Expand All @@ -132,28 +129,28 @@ describe('Content Collections - data collections', () => {
});

it(`Returns ${translationId}`, async () => {
expect(json).to.haveOwnProperty('id');
expect(json.id).to.equal(translationId);
assert.equal(json.hasOwnProperty('id'), true);
assert.equal(json.id, translationId);
});

it(`Generates correct data for ${translationId}`, async () => {
expect(json).to.haveOwnProperty('data');
expect(json.data).to.haveOwnProperty('homepage');
expect(json.data.homepage).to.haveOwnProperty('greeting');
expect(json.data.homepage).to.haveOwnProperty('preamble');
assert.equal(json.hasOwnProperty('data'), true);
assert.equal(json.data.hasOwnProperty('homepage'), true);
assert.equal(json.data.homepage.hasOwnProperty('greeting'), true);
assert.equal(json.data.homepage.hasOwnProperty('preamble'), true);

switch (translationId) {
case 'en':
expect(json.data.homepage.greeting).to.equal('Hello World!');
expect(json.data.homepage.preamble).to.equal('Welcome to the future of content.');
assert.equal(json.data.homepage.greeting, 'Hello World!');
assert.equal(json.data.homepage.preamble, 'Welcome to the future of content.');
break;
case 'es':
expect(json.data.homepage.greeting).to.equal('¡Hola Mundo!');
expect(json.data.homepage.preamble).to.equal('Bienvenido al futuro del contenido.');
assert.equal(json.data.homepage.greeting, '¡Hola Mundo!');
assert.equal(json.data.homepage.preamble, 'Bienvenido al futuro del contenido.');
break;
case 'fr':
expect(json.data.homepage.greeting).to.equal('Bonjour le monde!');
expect(json.data.homepage.preamble).to.equal('Bienvenue dans le futur du contenu.');
assert.equal(json.data.homepage.greeting, 'Bonjour le monde!');
assert.equal(json.data.homepage.preamble, 'Bienvenue dans le futur du contenu.');
break;
}
});
Expand Down
27 changes: 27 additions & 0 deletions packages/astro/test/debug-component.nodetest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import assert from 'node:assert/strict';
import { after, describe, before, it } from 'node:test';
import { loadFixture, isMacOS } from './test-utils.js';

// TODO: fix this tests in macOS
if (!isMacOS) {
describe('<Debug />', () => {
/** @type {import('./test-utils').Fixture} */
let fixture;
/** @type {import('./test-utils').DevServer} */
let devServer;

before(async () => {
fixture = await loadFixture({ root: './fixtures/debug-component/' });
devServer = await fixture.startDevServer();
});

after(async () => {
await devServer.stop();
});

it('Works in markdown pages', async () => {
const response = await fixture.fetch('/posts/first');
assert.equal(response.status, 200);
});
});
}
29 changes: 0 additions & 29 deletions packages/astro/test/debug-component.test.js

This file was deleted.

Loading

0 comments on commit 8c14143

Please sign in to comment.