Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: move unit tests from tests/ to test/ #868

Merged
merged 2 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ proto/build
!/drizzle/**/*.sql
.eslintcache
docs/api/html/*
tests/fixtures/config/*.zip
test/fixtures/config/*.zip
2 changes: 1 addition & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/dist/
/drizzle/*/meta/
/src/generated/
/tests/fixtures/
/test/fixtures/
/docs/
/coverage/
/proto/build/
2 changes: 1 addition & 1 deletion benchmarks/datastore.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import benchmark from 'nanobench'
import { createDataStore } from '../tests/helpers/datastore.js'
import { createDataStore } from '../test/helpers/datastore.js'

const datastore = await createDataStore({
dataTypes: [
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"test": "npm-run-all lint test:prettier build:types type test:buildConfigs test:unit test:e2e test:types",
"test:prettier": "prettier --check .",
"test:buildConfigs": "node scripts/build-config-fixtures.js",
"test:unit": "node --test tests/*.js tests/**/*.js",
"test:unit": "node --test",
"test:e2e": "node --test test-e2e/*.js test-e2e/**/*.js",
"test:types": "tsc -p test-types/tsconfig.json",
"build:types": "tsc -p tsconfig.npm.json && cpy 'src/**/*.d.ts' dist",
Expand Down
6 changes: 2 additions & 4 deletions scripts/build-config-fixtures.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@ import * as fs from 'node:fs/promises'
import { createWriteStream } from 'node:fs'
import { join, relative } from 'node:path'

const CONFIG_FIXTURES_PATH = new URL(
'../tests/fixtures/config',
import.meta.url
).pathname
const CONFIG_FIXTURES_PATH = new URL('../test/fixtures/config', import.meta.url)
.pathname
const dir = await fs.readdir(CONFIG_FIXTURES_PATH, { withFileTypes: true })
console.log('zipping config fixtures')
for (const fileOrFolder of dir) {
Expand Down
4 changes: 2 additions & 2 deletions src/datastore/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ The `DataStore` class is an API over a CoreManager namespace, responsible for re

The `DataStore` class is used internally by the [`DataType`](../datatype/) class.

An example of `DataStore` usage taken from the [datastore tests](../../tests/datastore.js):
An example of `DataStore` usage taken from the [datastore tests](../../test/datastore.js):

```js
const datastore = new DataStore({
Expand Down Expand Up @@ -43,4 +43,4 @@ TODO!

## Tests

Tests for this module are in [tests/datastore.js](../../tests/datastore.js)
Tests for this module are in [test/datastore.js](../../test/datastore.js)
2 changes: 1 addition & 1 deletion src/datatype/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ TODO!

## Tests

Tests for this module are in [tests/datatype.js](../../tests/datatype.js)
Tests for this module are in [test/datatype.js](../../test/datatype.js)
4 changes: 2 additions & 2 deletions test-e2e/config-import.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import test from 'node:test'
import assert from 'node:assert/strict'
import { createManager } from './utils.js'
import { defaultConfigPath } from '../tests/helpers/default-config.js'
import { defaultConfigPath } from '../test/helpers/default-config.js'

test(' config import - load default config when passed a path to `createProject`', async (t) => {
const manager = createManager('device0', t)
Expand Down Expand Up @@ -78,7 +78,7 @@ test('deletion of data before loading a new config', async (t) => {

// load another config
await project.importConfig({
configPath: './tests/fixtures/config/validConfig.zip',
configPath: './test/fixtures/config/validConfig.zip',
})

// load default config again
Expand Down
8 changes: 4 additions & 4 deletions test-e2e/manager-basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import RAM from 'random-access-memory'
import { MapeoManager } from '../src/mapeo-manager.js'
import Fastify from 'fastify'
import { getExpectedConfig } from './utils.js'
import { defaultConfigPath } from '../tests/helpers/default-config.js'
import { defaultConfigPath } from '../test/helpers/default-config.js'
import { kDataTypes } from '../src/mapeo-project.js'
import { hashObject } from '../src/utils.js'

Expand Down Expand Up @@ -133,7 +133,7 @@ test('Consistent loading of config', async (t) => {

const expectedDefault = await getExpectedConfig(defaultConfigPath)
const expectedMinimal = await getExpectedConfig(
'tests/fixtures/config/completeConfig.zip'
'test/fixtures/config/completeConfig.zip'
)
const projectId = await manager.createProject()
const project = await manager.getProject(projectId)
Expand Down Expand Up @@ -173,7 +173,7 @@ test('Consistent loading of config', async (t) => {
)

await t.test('loading non-default config when creating project', async () => {
const configPath = 'tests/fixtures/config/completeConfig.zip'
const configPath = 'test/fixtures/config/completeConfig.zip'
const projectId = await manager.createProject({ configPath })

const project = await manager.getProject(projectId)
Expand Down Expand Up @@ -210,7 +210,7 @@ test('Consistent loading of config', async (t) => {
await t.test(
'load different config and check if correctly loaded',
async () => {
const configPath = 'tests/fixtures/config/completeConfig.zip'
const configPath = 'test/fixtures/config/completeConfig.zip'
await project.importConfig({ configPath })
const projectPresets = await project.preset.getMany()
assert.deepEqual(
Expand Down
6 changes: 3 additions & 3 deletions test-e2e/manager-fastify-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ import { FastifyController } from '../src/fastify-controller.js'
import { plugin as StaticMapsPlugin } from '../src/fastify-plugins/maps/static-maps.js'
import { plugin as MapServerPlugin } from '../src/fastify-plugins/maps/index.js'
import { plugin as OfflineFallbackMapPlugin } from '../src/fastify-plugins/maps/offline-fallback-map.js'
import { blobMetadata } from '../tests/helpers/blob-store.js'
import { blobMetadata } from '../test/helpers/blob-store.js'

const BLOB_FIXTURES_DIR = fileURLToPath(
new URL('../tests/fixtures/blob-api/', import.meta.url)
new URL('../test/fixtures/blob-api/', import.meta.url)
)

const MAP_FIXTURES_PATH = new URL('../tests/fixtures/maps', import.meta.url)
const MAP_FIXTURES_PATH = new URL('../test/fixtures/maps', import.meta.url)
.pathname

const MAPEO_FALLBACK_MAP_PATH = new URL(
Expand Down
8 changes: 4 additions & 4 deletions test-e2e/sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ import {
waitForSync,
} from './utils.js'
import { kCoreManager } from '../src/mapeo-project.js'
import { getKeys } from '../tests/helpers/core-manager.js'
import { getKeys } from '../test/helpers/core-manager.js'
import { NAMESPACES, PRESYNC_NAMESPACES } from '../src/constants.js'
import { FastifyController } from '../src/fastify-controller.js'
import { generate } from '@mapeo/mock-data'
import { valueOf } from '../src/utils.js'
import pTimeout from 'p-timeout'
import { BLOCKED_ROLE_ID, COORDINATOR_ROLE_ID } from '../src/roles.js'
import { kSyncState } from '../src/sync/sync-api.js'
import { blobMetadata } from '../tests/helpers/blob-store.js'
import { blobMetadata } from '../test/helpers/blob-store.js'
/** @import { State } from '../src/sync/sync-api.js' */

const SCHEMAS_INITIAL_SYNC = ['preset', 'field']
Expand Down Expand Up @@ -138,7 +138,7 @@ test('syncing blobs', async (t) => {
const [invitorProject, inviteeProject] = projects

const fixturePath = new URL(
'../tests/fixtures/images/02-digidem-logo.jpg',
'../test/fixtures/images/02-digidem-logo.jpg',
import.meta.url
).pathname

Expand Down Expand Up @@ -347,7 +347,7 @@ test('auto-stop', async (t) => {
await clock.tickAsync(9000)

const fixturePath = new URL(
'../tests/fixtures/images/02-digidem-logo.jpg',
'../test/fixtures/images/02-digidem-logo.jpg',
import.meta.url
).pathname
const blob = await invitorProject.$blobs.create(
Expand Down
2 changes: 1 addition & 1 deletion test-e2e/translation-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import test from 'node:test'
import assert from 'node:assert/strict'
import { isDefined } from '../src/utils.js'
import { createManagers, ManagerCustodian } from './utils.js'
import { defaultConfigPath } from '../tests/helpers/default-config.js'
import { defaultConfigPath } from '../test/helpers/default-config.js'
import {
fieldsTranslationMap,
fieldTranslations,
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
46 changes: 23 additions & 23 deletions tests/config-import.js → test/config-import.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ test('config import - loading', async () => {
)

await assert.rejects(
async () => await readConfig('./tests/fixtures/config/notAZip.txt'),
async () => await readConfig('./test/fixtures/config/notAZip.txt'),
/End of Central Directory Record not found/,
'not a zip file'
)
Expand All @@ -34,89 +34,89 @@ test('config import - loading', async () => {

await assert.rejects(
async () =>
await readConfig('./tests/fixtures/config/configWithoutPresets.zip'),
await readConfig('./test/fixtures/config/configWithoutPresets.zip'),
/Error: Zip file does not contain presets.json/,
'missing presets.json'
)

await assert.rejects(
async () =>
await readConfig('./tests/fixtures/config/invalidPresetsJSON.zip'),
await readConfig('./test/fixtures/config/invalidPresetsJSON.zip'),
/Error: Could not parse presets.json/,
'JSON.parse error of presets.json'
)

await assert.rejects(
async () =>
await readConfig('./tests/fixtures/config/invalidPresetsFile.zip'),
await readConfig('./test/fixtures/config/invalidPresetsFile.zip'),
/Error: Invalid presets.json file/,
'presets.json is not an object'
)

await assert.rejects(
async () =>
await readConfig('./tests/fixtures/config/missingPresetsField.zip'),
await readConfig('./test/fixtures/config/missingPresetsField.zip'),
/Error: Invalid presets.json file/,
'no presets field in presets.json'
)

await assert.rejects(
async () =>
await readConfig('./tests/fixtures/config/presetsFieldNotAnObject.zip'),
await readConfig('./test/fixtures/config/presetsFieldNotAnObject.zip'),
/Error: Invalid presets.json file/,
'presets field in presets.json is not an object'
)

await assert.rejects(
async () =>
await readConfig('./tests/fixtures/config/missingFieldsField.zip'),
await readConfig('./test/fixtures/config/missingFieldsField.zip'),
/Error: Invalid presets.json file/,
'no fields field in presets.json'
)

await assert.rejects(
async () =>
await readConfig('./tests/fixtures/config/fieldsFieldNotAnObject.zip'),
await readConfig('./test/fixtures/config/fieldsFieldNotAnObject.zip'),
/Error: Invalid presets.json file/,
'fields field in presets.json is not an object'
)

await assert.rejects(
async () => await readConfig('./tests/fixtures/config/missingMetadata.zip'),
async () => await readConfig('./test/fixtures/config/missingMetadata.zip'),
/Zip file does not contain metadata.json/,
''
)

await assert.rejects(
async () => await readConfig('./tests/fixtures/config/invalidMetadata.zip'),
async () => await readConfig('./test/fixtures/config/invalidMetadata.zip'),
/Could not parse metadata.json/,
''
)

await assert.rejects(
async () =>
await readConfig('./tests/fixtures/config/invalidMetadataKey.zip'),
await readConfig('./test/fixtures/config/invalidMetadataKey.zip'),
/Error: Invalid structure of metadata file/,
''
)

await assert.rejects(
async () =>
await readConfig('./tests/fixtures/config/invalidMetadataValue.zip'),
await readConfig('./test/fixtures/config/invalidMetadataValue.zip'),
/Error: Invalid structure of metadata file/,
''
)

assert(
await readConfig('./tests/fixtures/config/validConfig.zip'),
await readConfig('./test/fixtures/config/validConfig.zip'),
'valid zip'
)
})

test('config import - icons', async () => {
// filename
let config = await readConfig(
'./tests/fixtures/config/invalidIconFilename.zip'
'./test/fixtures/config/invalidIconFilename.zip'
)
await arrayFrom(config.icons())
assert.equal(
Expand All @@ -131,7 +131,7 @@ test('config import - icons', async () => {

// pixel density
config = await readConfig(
'./tests/fixtures/config/invalidIconPixelDensity.zip'
'./test/fixtures/config/invalidIconPixelDensity.zip'
)

await arrayFrom(config.icons())
Expand All @@ -147,7 +147,7 @@ test('config import - icons', async () => {
)

// size
config = await readConfig('./tests/fixtures/config/invalidIconSize.zip')
config = await readConfig('./test/fixtures/config/invalidIconSize.zip')

await arrayFrom(config.icons())
assert.equal(
Expand All @@ -160,7 +160,7 @@ test('config import - icons', async () => {
'the error message is about invalid size'
)

config = await readConfig('./tests/fixtures/config/validIcons.zip')
config = await readConfig('./test/fixtures/config/validIcons.zip')
const icons = await arrayFrom(config.icons())
assert.equal(icons.length, 2)
for (const icon of icons) {
Expand All @@ -177,7 +177,7 @@ test('config import - icons', async () => {
})

test('config import - fields', async () => {
let config = await readConfig('./tests/fixtures/config/invalidField.zip')
let config = await readConfig('./test/fixtures/config/invalidField.zip')
arrayFrom(config.fields())
assert.equal(config.warnings.length, 3, 'we got 3 errors when reading fields')
assert(
Expand All @@ -193,7 +193,7 @@ test('config import - fields', async () => {
'the third error is because the field is not an object'
)

config = await readConfig('./tests/fixtures/config/validField.zip')
config = await readConfig('./test/fixtures/config/validField.zip')
for (const field of config.fields()) {
assert.equal(field.name, 'nombre-monitor', `field.name is 'nombre-monitor'`)
assert.equal(
Expand All @@ -207,7 +207,7 @@ test('config import - fields', async () => {
})

test('config import - presets', async () => {
let config = await readConfig('./tests/fixtures/config/invalidPreset.zip')
let config = await readConfig('./test/fixtures/config/invalidPreset.zip')
arrayFrom(config.presets())
assert.equal(
config.warnings.length,
Expand All @@ -223,7 +223,7 @@ test('config import - presets', async () => {
'the second error is because the preset is null'
)

config = await readConfig('./tests/fixtures/config/noIconNameOnPreset.zip')
config = await readConfig('./test/fixtures/config/noIconNameOnPreset.zip')
arrayFrom(config.presets())
assert.equal(
config.warnings.length,
Expand All @@ -236,15 +236,15 @@ test('config import - presets', async () => {
)

config = await readConfig(
'./tests/fixtures/config/invalidIconNameOnPreset.zip'
'./test/fixtures/config/invalidIconNameOnPreset.zip'
)
arrayFrom(config.presets())
assert(
/preset references icon with name/.test(config.warnings[0].message),
"there's a warning because the preset references a missing icon"
)

config = await readConfig('./tests/fixtures/config/validPreset.zip')
config = await readConfig('./test/fixtures/config/validPreset.zip')
for (const preset of config.presets()) {
assert.equal(preset.value.schemaName, 'preset', `schemaName is 'preset'`)
assert(
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
Loading
Loading