Skip to content

Commit

Permalink
Move test configs to individual packages (#1134)
Browse files Browse the repository at this point in the history
* Move test configs to individual packages

* build:typechain

* package-lock.json && ignore next-env.d.ts when adding licenses

* Add licenses

* Copy test env file to root of repo for GHA

* change expected dir for .env file

* Fix some more package directory stuff

* add missing env files

* Add missing env file

* remove --if-present so that we error on missing test command

* add some more missing test commands

* Remove error from message

* add two more missing test commands

* Add test command for procaptcha
  • Loading branch information
forgetso authored Apr 8, 2024
1 parent c6d293d commit b8b0614
Show file tree
Hide file tree
Showing 62 changed files with 263 additions and 52 deletions.
1 change: 1 addition & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ jobs:
run: |
cp demos/client-example-server/env.development demos/client-example-server/.env.test
cp demos/client-example/env.development demos/client-example/.env.test
cp dev/scripts/env.test .env.test
cp dev/scripts/env.test dev/scripts/.env.test
cp dev/scripts/env.test packages/cli/.env.test
cp dev/scripts/env.test packages/procaptcha-bundle/.env.test
Expand Down
1 change: 1 addition & 0 deletions contracts/captcha/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
}
},
"scripts": {
"test": "echo \"No test specified\"",
"clean": "tsc --build --clean",
"build": "tsc --build --verbose",
"build:cjs": "npx vite --config vite.cjs.config.ts build",
Expand Down
2 changes: 1 addition & 1 deletion contracts/captcha/src/captcha.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"source": {
"hash": "0x51a3d42da3fc226f62214bd208e3987e4685705e0c53e31c612e7455415c1a65",
"hash": "0x5aa8a3bfa2e7f3f8a77898e0b3faa5d16565661ce88a236c78fc1e2148cddab8",
"language": "ink! 4.3.0",
"compiler": "rustc 1.69.0",
"build_info": {
Expand Down
4 changes: 2 additions & 2 deletions contracts/captcha/src/contract-info/captcha.ts

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions contracts/common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"main": "dist/index.js",
"type": "module",
"scripts": {
"test": "echo \"No test specified\"",
"clean": "tsc --build --clean",
"build": "tsc --build --verbose",
"eslint": "npx eslint . --no-error-on-unmatched-pattern --ignore-path ../../.eslintignore",
Expand Down
2 changes: 1 addition & 1 deletion contracts/common/src/common.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"source": {
"hash": "0x15555e2899f4226a4f845ce6ddc85d4c9f468425965e36dcbf50861235081181",
"hash": "0xd56c0625dd09b22066b9c1e4c8ee4d92abe89ad2900476881f604df61008d4f7",
"language": "ink! 4.3.0",
"compiler": "rustc 1.69.0",
"build_info": {
Expand Down
4 changes: 2 additions & 2 deletions contracts/common/src/contract-info/common.ts

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions contracts/proxy/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"main": "dist/index.js",
"type": "module",
"scripts": {
"test": "echo \"No test specified\"",
"clean": "tsc --build --clean",
"build": "tsc --build --verbose",
"eslint": "npx eslint . --no-error-on-unmatched-pattern --ignore-path ../../.eslintignore",
Expand Down
4 changes: 2 additions & 2 deletions contracts/proxy/src/contract-info/proxy.ts

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion contracts/proxy/src/proxy.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"source": {
"hash": "0x7694d5027227d2bf7e6074d7d9c08eeebb29c93584fbe1996bdc450c74739bdb",
"hash": "0x9ab7a1214c6c2a76bfba925a6285e4101d3592801a4311ab7ab1247514669ff1",
"language": "ink! 4.3.0",
"compiler": "rustc 1.69.0",
"build_info": {
Expand Down
1 change: 1 addition & 0 deletions demos/client-bundle-example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"npm": ">=9"
},
"scripts": {
"test": "echo \"No test specified\"",
"start": "vite serve ./src --port 9232 --config vite.config.ts",
"clean": "echo 'nothing to clean'",
"eslint": "npx eslint . --no-error-on-unmatched-pattern --ignore-path ../../.eslintignore",
Expand Down
2 changes: 1 addition & 1 deletion demos/client-bundle-example/src/jsBundleTest.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<div
class="procaptcha"
data-theme="light"
data-sitekey="5HGjWAeFDfFCWPsjFQdVV2Msvz2XtMktvgocEZcCj68kUMaw"
data-sitekey="5HUBceb4Du6dvMA9BiwN5VzUrzUsX9Zp7z7nSR2cC1TCv5jg"
></div>
</form>
</body>
Expand Down
1 change: 1 addition & 0 deletions demos/client-example-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"npm": ">=9"
},
"scripts": {
"test": "echo \"No test specified\"",
"dev": "vite serve --mode=development --config ./vite.config.ts --host",
"start": "node ./dist/app.js",
"start:bundle": "node ./dist/bundle/prosopo_client_example_server.app.bundle.js",
Expand Down
1 change: 1 addition & 0 deletions demos/client-example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"typescript": "5.1.6"
},
"scripts": {
"test": "echo \"No test specified\"",
"start": "vite serve --mode=development --config vite.config.ts --port 9230 --host --force",
"build": "tsc --build --verbose",
"bundle:prod": "vite build --mode=production --config vite.config.ts --outDir dist --emptyOutDir",
Expand Down
1 change: 1 addition & 0 deletions demos/client-frictionless-example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"typescript": "5.1.6"
},
"scripts": {
"test": "echo \"No test specified\"",
"start": "vite serve --mode=development --config vite.config.ts --port 9240 --host --force",
"build": "tsc --build --verbose",
"bundle:prod": "vite build --mode=production --config vite.config.ts --outDir dist --emptyOutDir",
Expand Down
1 change: 1 addition & 0 deletions demos/client-pow-example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"typescript": "5.1.6"
},
"scripts": {
"test": "echo \"No test specified\"",
"start": "vite serve --mode=development --config vite.config.ts --port 9240 --host --force",
"build": "tsc --build --verbose",
"bundle:prod": "vite build --mode=production --config vite.config.ts --outDir dist --emptyOutDir",
Expand Down
1 change: 1 addition & 0 deletions demos/cypress-shared/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"vite-plugin-node-polyfills": "^0.21.0"
},
"scripts": {
"test": "echo \"No test specified\"",
"build": "tsc",
"clean": "tsc --build --clean",
"cypress:open:client-example": "CYPRESS_BASE_URL='http://0.0.0.0:9230' cypress open",
Expand Down
1 change: 1 addition & 0 deletions demos/provider-mock/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"npm": ">=9"
},
"scripts": {
"test": "echo \"No test specified\"",
"clean": "tsc --build --clean",
"build": "tsc --build --verbose tsconfig.json",
"eslint": "npx eslint . --no-error-on-unmatched-pattern --ignore-path ../../.eslintignore",
Expand Down
1 change: 1 addition & 0 deletions dev/config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"main": "./dist/index.js",
"type": "module",
"scripts": {
"test": "echo \"No test specified\"",
"clean": "tsc --build --clean",
"build": "tsc --build --verbose",
"eslint": "npx eslint . --no-error-on-unmatched-pattern --ignore-path ../../.eslintignore",
Expand Down
5 changes: 2 additions & 3 deletions dev/config/src/vite/vite.test.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.
import { defineConfig } from 'vitest/config'
import { getRootDir } from '../projectInfo.js'
import VitePluginCloseAndCopy from './vite-plugin-close-and-copy.js'
import VitePluginSourcemapExclude from './vite-plugin-sourcemap-exclude.js'

Expand All @@ -30,8 +29,8 @@ export default function () {
},
},
test: {
root: getRootDir(),
include: ['packages/*/src/**/*.{test,spec}.?(c|m)[jt]s?(x)'],
//root: getRootDir(),
include: ['src/**/*.{test,spec}.?(c|m)[jt]s?(x)'],
watch: false,
watchExclude: ['**/node_modules/**', '**/dist/**'],
logHeapUsage: true,
Expand Down
2 changes: 1 addition & 1 deletion dev/flux/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
"npm": ">=9"
},
"scripts": {
"test": "echo \"No test specified\"",
"clean": "tsc --build --clean",
"build": "tsc --build --verbose",
"build:cjs": "npx vite --config vite.cjs.config.ts build",
"test": "NODE_OPTIONS=--max-old-space-size=4096 npx vitest run --config ./src/vite.config.ts",
"cli": "node dist/index.js",
"eslint": "npx eslint . --no-error-on-unmatched-pattern --ignore-path ../../.eslintignore",
"eslint:fix": "npm run eslint -- --fix",
Expand Down
1 change: 1 addition & 0 deletions dev/gh-actions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"description": "",
"private": true,
"scripts": {
"test": "echo \"No test specified\"",
"clean": "tsc --build --clean",
"build": "tsc --build --verbose",
"start": "npx tsx src/index.ts",
Expand Down
2 changes: 1 addition & 1 deletion dev/scripts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
"npm": ">=9"
},
"scripts": {
"test": "echo \"No test specified\"",
"clean": "tsc --build --clean",
"build": "tsc --build --verbose",
"test": "npx vitest run --config ./src/vite.config.ts",
"deploy": "node dist/deploy/protocol.js",
"cli": "node dist/cli/index.js",
"setup": "node dist/cli/index.js setup",
Expand Down
1 change: 1 addition & 0 deletions dev/scripts/src/scripts/addCopyrightNotice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ const files = glob
'**/vite.cjs.config.ts.timestamp*',
'**/js_bundles_host_temp/**',
'**/client-bundle-example/src/assets/**',
'**/next-env.d.ts/**',
],
})
.filter((file) => fs.lstatSync(file).isFile())
Expand Down
1 change: 1 addition & 0 deletions dev/tsconfig-checker/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"description": "",
"private": true,
"scripts": {
"test": "echo \"No test specified\"",
"clean": "tsc --build --clean",
"build": "tsc --build --verbose",
"start": "npx tsx src/check.ts",
Expand Down
5 changes: 5 additions & 0 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"start:all": "npx concurrently \"npm run start:server\" \"npm run start:provider\" \"npm run start:demo\" \"npm run start:bundle\" --kill-others",
"start:all:pow": "npx concurrently \"npm run start:server\" \"npm run start:provider\" \"npm run start:demo:pow\" \"npm run start:bundle\" --kill-others",
"populate-data": "npm -w @prosopo/provider run populate-data",
"test": "npm -w @prosopo/scripts run test",
"test": "npm run --workspaces test",
"test:all": "npm run --workspaces --if-present test",
"eslint": "npm --workspaces run eslint && npm run eslint:workspace",
"eslint:workspace": "npx eslint '.*.*' '*.*' .vscode .github --ignore-pattern README.md --ignore-pattern diagram.svg --ignore-path .eslintignore",
Expand Down
1 change: 1 addition & 0 deletions packages/account/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
}
},
"scripts": {
"test": "echo \"No test specified\"",
"clean": "tsc --build --clean",
"build": "tsc --build --verbose tsconfig.json",
"build:cjs": "npx vite --config vite.cjs.config.ts build",
Expand Down
1 change: 1 addition & 0 deletions packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
}
},
"scripts": {
"test": "echo \"No test specified\"",
"clean": "tsc --build --clean",
"build": "tsc --build --verbose",
"build:cjs": "npx vite --config vite.cjs.config.ts build",
Expand Down
1 change: 1 addition & 0 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"build:cjs": "npx vite --config vite.cjs.config.ts build",
"bundle:dev": "vite build --config vite.config.ts --mode development",
"bundle:prod": "vite build --config vite.config.ts --mode production",
"test": "npx vitest run --config ./vite.test.config.ts",
"cli": "node ./dist/cli.js",
"start": "node ./dist/cli.js --api",
"eslint": "npx eslint . --no-error-on-unmatched-pattern --ignore-path ../../.eslintignore",
Expand Down
7 changes: 2 additions & 5 deletions packages/cli/src/tests/bundle/bundle.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,14 @@
// limitations under the License.
import { assert, describe, test } from 'vitest'
import { exec } from 'child_process'
import { getCurrentFileDirectory } from '@prosopo/util'
import { getCliPkgDir } from '@prosopo/config'
import { promisify } from 'util'
const execPromise = promisify(exec)

describe('provider bundle', () => {
test('bundle runs after bundling', async () => {
// get file location
const dir = getCurrentFileDirectory(import.meta.url)

// get root directory of this package
const rootDir = dir.split('/').slice(0, -3).join('/')
const rootDir = getCliPkgDir()

// build bundle
await execPromise(`cd ${rootDir} && npm run bundle:prod`)
Expand Down
29 changes: 19 additions & 10 deletions packages/cli/src/tests/reloader.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,39 +12,48 @@
// See the License for the specific language governing permissions and
// limitations under the License.
import { describe, expect, test } from 'vitest'
import { getCurrentFileDirectory } from '@prosopo/util'
import { getCliPkgDir, getRootDir } from '@prosopo/config'
import { promisify } from 'util'
import { spawn } from 'child_process'
import fs from 'fs'
import path from 'path'

describe('reloading api', () => {
test('api reloads after changing .env file', () => {
// get file location
const dir = getCurrentFileDirectory(import.meta.url)

// get root directory of this package
const rootDir = dir.split('/').slice(0, -2).join('/')
// check for the env file in either the root or the package directory
const envFile = `.env.${process.env.NODE_ENV || 'development'}`
console.log('env file ', envFile)
const rootDir = getRootDir()
const packageDir = getCliPkgDir()
const rootEnvPath = `${rootDir}/${envFile}`
const packageEnvPath = `${packageDir}/${envFile}`
let envPath = ''
if (fs.existsSync(rootEnvPath)) {
envPath = path.resolve(rootEnvPath)
} else if (fs.existsSync(packageEnvPath)) {
envPath = path.resolve(packageEnvPath)
} else {
throw new Error(`No ${envFile} file found`)
}

const restoreEnv = async () => {
const envPath = path.resolve(`${rootDir}/.env.test`)
const envContent = await promisify(fs.readFile)(envPath, 'utf8')
const newEnvContent = envContent.replace('\nTEST=TEST', '')
await promisify(fs.writeFile)(envPath, newEnvContent)
}

return new Promise<void>((resolve, reject) => {
console.log('rootDir', rootDir)
console.log('packageDir', packageDir)

// run API
const child = spawn(`npm`, ['run', 'cli', '--', '--api'], {
cwd: rootDir,
cwd: packageDir,
env: { ...process.env, NODE_ENV: 'test' },
})

let appended = false
child.stdout.on('data', (data) =>
onData(data, rootDir, appended).then((result) => {
onData(data, packageDir, appended).then((result) => {
appended = result.appended
const kill = result.kill
// console.log('onData ran, appended', appended, 'kill', kill)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,21 @@
// See the License for the specific language governing permissions and
// limitations under the License.
import { ViteTestConfig } from '@prosopo/config'
import { loadEnv } from '@prosopo/cli'
import dotenv from 'dotenv'
import fs from 'fs'
import path from 'path'
process.env.NODE_ENV = 'test'
loadEnv(path.resolve())
// if .env.test exists at this level, use it, otherwise use the one at the root
const envFile = `.env.${process.env.NODE_ENV || 'development'}`
let envPath = envFile
if (fs.existsSync(envFile)) {
envPath = path.resolve(envFile)
} else if (fs.existsSync(`../../${envFile}`)) {
envPath = path.resolve(`../../${envFile}`)
} else {
throw new Error(`No ${envFile} file found`)
}

dotenv.config({ path: envPath })

export default ViteTestConfig
3 changes: 2 additions & 1 deletion packages/common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"clean": "tsc --build --clean",
"build": "tsc --build --verbose",
"build:cjs": "npx vite --config vite.cjs.config.ts build",
"test": "NODE_ENV=test vitest --run",
"test": "npx vitest run --config ./vite.test.config.ts",
"eslint": "npx eslint . --no-error-on-unmatched-pattern --ignore-path ../../.eslintignore",
"eslint:fix": "npm run eslint -- --fix",
"prettier": "npx prettier . --check --no-error-on-unmatched-pattern --ignore-path ../../.eslintignore",
Expand Down Expand Up @@ -47,6 +47,7 @@
},
"devDependencies": {
"@prosopo/config": "0.3.5",
"dotenv": "^16.0.1",
"tslib": "2.6.2",
"typescript": "5.1.6",
"vitest": "^1.3.1"
Expand Down
Loading

0 comments on commit b8b0614

Please sign in to comment.