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

Rename test dirs #1088

Merged
merged 13 commits into from
Mar 7, 2024
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -137,5 +137,5 @@ chain-data
# ignore vite config timestamps
vite.config.ts.timestamp*

# ignore test results dir
**/tests/**/test_results
# ignore our cache dir
.cache
8 changes: 8 additions & 0 deletions dev/config/src/projectInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ export const getRootDir = () => {
return new URL('../../..', import.meta.url).pathname.slice(0, -1)
}

export const getCacheDir = () => {
return `${getRootDir()}/.cache`
}

export const getTestResultsDir = () => {
return `${getCacheDir()}/test-results`
}

export const getDevDir = () => {
return `${getRootDir()}/dev`
}
Expand Down
2 changes: 1 addition & 1 deletion dev/config/src/vite/vite.test.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default function () {
root: getRootDir(),
include: ['packages/*/src/**/*.{test,spec}.?(c|m)[jt]s?(x)'],
watch: false,
watchExclude: ['**/node_modules/**', '**/dist/**', '../../packages/datasets-fs/src/tests/data/**'],
watchExclude: ['**/node_modules/**', '**/dist/**'],
logHeapUsage: true,
coverage: {
enabled: true,
Expand Down
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/datasets-fs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"dependencies": {
"@polkadot/util": "12.6.1",
"@prosopo/common": "0.3.1",
"@prosopo/config": "0.3.1",
"@prosopo/types": "0.3.1",
"@prosopo/util": "0.3.1",
"bcrypt": "^5.1.0",
Expand Down
28 changes: 17 additions & 11 deletions packages/datasets-fs/src/tests/mocked.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,35 @@ import { Resize } from '../commands/resize.js'
import { afterAll, beforeAll, describe, test } from 'vitest'
import { blake2b } from '@noble/hashes/blake2b'
import { captchasEqFs, fsEq, fsWalk, restoreRepoDir, substituteRepoDir } from './utils.js'
import { getRootDir, getTestResultsDir } from '@prosopo/config'
import { u8aToHex } from '@polkadot/util/u8a'
import fs from 'fs'
import path from 'path'
import sharp from 'sharp'

describe('dataset commands', () => {
const pkgDir = path.relative(getRootDir(), __dirname)
const pkgInternalPath = pkgDir.replace(`${__dirname}/`, '')
const testResultsDir = `${getTestResultsDir()}/${pkgInternalPath}`

beforeAll(() => {
// substitute the repo path in the data for tests
substituteRepoDir()
// remove previous test results
if (fs.existsSync(`${__dirname}/test_results`)) {
fs.rmdirSync(`${__dirname}/test_results`, { recursive: true })
}
fs.mkdirSync(`${__dirname}/test_results`, { recursive: true })
fs.mkdirSync(`${testResultsDir}`, { recursive: true })
})

afterAll(() => {
// restore repo path back to placeholder
restoreRepoDir()
// remove test results
if (fs.existsSync(`${testResultsDir}`)) {
fs.rmdirSync(`${testResultsDir}`, { recursive: true })
}
})

test('labels', async () => {
const input = `${__dirname}/data/flat_resized/data.json`
const output = `${__dirname}/test_results/labels.json`
const output = `${testResultsDir}/labels.json`
const labels = new Labels()
labels.logger.setLogLevel('error')
await labels.exec({
Expand All @@ -52,7 +58,7 @@ describe('dataset commands', () => {

test('generate v2', async () => {
const input = `${__dirname}/data/flat_resized/data.json`
const output = `${__dirname}/test_results/captchas_v2.json`
const output = `${testResultsDir}/captchas_v2.json`
const minIncorrect = 1
const minCorrect = 1
const minLabelled = 2
Expand Down Expand Up @@ -120,7 +126,7 @@ describe('dataset commands', () => {

test('generate v1', async () => {
const input = `${__dirname}/data/flat_resized/data.json`
const output = `${__dirname}/test_results/captchas_v1.json`
const output = `${testResultsDir}/captchas_v1.json`
const generate = new GenerateV1()
generate.logger.setLogLevel('error')
await generate.exec({
Expand All @@ -143,7 +149,7 @@ describe('dataset commands', () => {

test('resizes data', async () => {
const input = `${__dirname}/data/flat/data.json`
const output = `${__dirname}/test_results/flat_resized`
const output = `${testResultsDir}/flat_resized`
const resize = new Resize()
resize.logger.setLogLevel('error')
await resize.exec({
Expand Down Expand Up @@ -174,7 +180,7 @@ describe('dataset commands', () => {

test('relocates data', async () => {
const input = `${__dirname}/data/flat_resized/data.json`
const output = `${__dirname}/test_results/relocated_data.json`
const output = `${testResultsDir}/relocated_data.json`
const relocate = new Relocate()
relocate.logger.setLogLevel('error')
await relocate.exec({
Expand All @@ -192,7 +198,7 @@ describe('dataset commands', () => {

test('flattens hierarchical data', async () => {
const input = `${__dirname}/data/hierarchical`
const output = `${__dirname}/test_results/flat`
const output = `${testResultsDir}/flat`
const flatten = new Flatten()
flatten.logger.setLogLevel('error')
await flatten.exec({
Expand Down
4 changes: 2 additions & 2 deletions packages/datasets/src/tests/captcha.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
Item,
MerkleProof,
} from '@prosopo/types'
import { NO_SOLUTION_VALUE, getSolutionValueToHash } from '../../src/captcha/index.js'
import { NO_SOLUTION_VALUE, getSolutionValueToHash } from '../captcha/index.js'
import { at, get } from '@prosopo/util'
import { beforeAll, describe, expect, test } from 'vitest'
import {
Expand All @@ -36,7 +36,7 @@ import {
parseCaptchaDataset,
sortAndComputeHashes,
verifyProof,
} from '../../src/captcha/index.js'
} from '../captcha/index.js'
import path from 'path'

describe('CAPTCHA FUNCTIONS', async function () {
Expand Down
Loading