Skip to content

Commit

Permalink
Remove internal usage of env.TEST (#677)
Browse files Browse the repository at this point in the history
  • Loading branch information
jycouet authored Nov 5, 2022
1 parent b7a07a3 commit 927146d
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 20 deletions.
5 changes: 5 additions & 0 deletions .changeset/tidy-boxes-fetch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'houdini': patch
---

fix - env.TEST is not used internally anymore
2 changes: 1 addition & 1 deletion packages/houdini-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"devDependencies": {
"@types/estraverse": "^5.1.2",
"@types/next": "^9.0.0",
"next": "^13.0.0",
"next": "^13.0.0",
"scripts": "workspace:^"
},
"dependencies": {
Expand Down
4 changes: 2 additions & 2 deletions packages/houdini/src/codegen/generators/runtime/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Config, siteURL as SITE_URL, fs, HoudiniError, path } from '../../../lib'
import { Config, siteURL as SITE_URL, fs, HoudiniError, path, houdini_mode } from '../../../lib'

export default async function runtimeGenerator(config: Config) {
// generate the adapter to normalize interactions with the framework
Expand All @@ -25,7 +25,7 @@ export default async function runtimeGenerator(config: Config) {
}

async function generatePluginRuntime(config: Config, plugin: Config['plugins'][number]) {
if (process.env.TEST) {
if (houdini_mode.is_testing) {
return
}

Expand Down
5 changes: 3 additions & 2 deletions packages/houdini/src/lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { fileURLToPath, pathToFileURL } from 'url'
import { ConfigFile, CachePolicy } from '../runtime/lib'
import { computeID, defaultConfigValues, keyFieldsForType } from '../runtime/lib/config'
import { TransformPage } from '../vite/houdini'
import { houdini_mode } from './constants'
import { HoudiniError } from './error'
import * as fs from './fs'
import { pullSchema } from './introspection'
Expand Down Expand Up @@ -304,7 +305,7 @@ export class Config {
get runtimeSource() {
// when running in the real world, scripts are nested in a sub directory of build, in tests they aren't nested
// under /src so we need to figure out how far up to go to find the appropriately compiled runtime
const relative = process.env.TEST
const relative = houdini_mode.is_testing
? path.join(currentDir, '..', '..')
: // start here and go to parent until we find the node_modules/houdini folder
this.findModule()
Expand Down Expand Up @@ -434,7 +435,7 @@ export class Config {
}

pluginDirectory(name: string) {
return process.env.TEST
return houdini_mode.is_testing
? path.resolve('../../../', name)
: path.join(this.rootDir, 'plugins', name)
}
Expand Down
10 changes: 10 additions & 0 deletions packages/houdini/src/lib/constants.ts
Original file line number Diff line number Diff line change
@@ -1 +1,11 @@
export const siteURL = 'https://houdinigraphql.com'

export const houdini_mode = {
/**
* to set the testing mode do like this:
* `process.env.HOUDINI_TEST = 'true'`
*/
get is_testing() {
return process.env.HOUDINI_TEST === 'true'
},
}
25 changes: 13 additions & 12 deletions packages/houdini/src/lib/fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import { glob as G } from 'glob'
import { fs as memfs, vol } from 'memfs'
import { promisify } from 'util'

import { houdini_mode } from './constants'
import * as path from './path'

export async function readFile(filepath: string): Promise<string | null> {
if (process.env.NODE_ENV === 'test') {
if (houdini_mode.is_testing) {
try {
if (filepath.includes('build/runtime')) {
return await fs.readFile(filepath, 'utf-8')
Expand All @@ -27,7 +28,7 @@ export async function readFile(filepath: string): Promise<string | null> {
}

export function readFileSync(filepath: string): string | null {
if (process.env.NODE_ENV === 'test') {
if (houdini_mode.is_testing) {
try {
if (filepath.includes('build/runtime')) {
return fsExtra.readFileSync(filepath, 'utf-8')
Expand All @@ -53,7 +54,7 @@ export async function writeFile(filepath: string, data: string) {
}

// no mock in tests
if (process.env.NODE_ENV === 'test') {
if (houdini_mode.is_testing) {
return memfs.writeFileSync(filepath, data)
}

Expand All @@ -62,7 +63,7 @@ export async function writeFile(filepath: string, data: string) {

export async function access(filepath: string) {
// no mock in production
if (process.env.NODE_ENV !== 'test') {
if (!houdini_mode.is_testing) {
return await fs.access(filepath)
}

Expand All @@ -77,7 +78,7 @@ export async function access(filepath: string) {

export async function mkdirp(filepath: string) {
// no mock in production
if (process.env.NODE_ENV !== 'test') {
if (!houdini_mode.is_testing) {
return await fsExtra.mkdirp(filepath)
}

Expand All @@ -86,7 +87,7 @@ export async function mkdirp(filepath: string) {

export async function mkdirpSync(filepath: string) {
// no mock in production
if (process.env.NODE_ENV !== 'test') {
if (!houdini_mode.is_testing) {
return fsExtra.mkdirpSync(filepath)
}

Expand All @@ -95,7 +96,7 @@ export async function mkdirpSync(filepath: string) {

export async function mkdir(filepath: string) {
// no mock in production
if (process.env.NODE_ENV !== 'test') {
if (!houdini_mode.is_testing) {
return await fs.mkdir(filepath)
}

Expand All @@ -104,7 +105,7 @@ export async function mkdir(filepath: string) {

export async function rmdir(filepath: string) {
// no mock in production
if (process.env.NODE_ENV !== 'test') {
if (!houdini_mode.is_testing) {
return await fs.rm(filepath, {
recursive: true,
})
Expand All @@ -115,7 +116,7 @@ export async function rmdir(filepath: string) {

export async function stat(filepath: string) {
// no mock in production
if (process.env.NODE_ENV !== 'test') {
if (!houdini_mode.is_testing) {
return await fs.stat(filepath)
}

Expand All @@ -129,7 +130,7 @@ export async function stat(filepath: string) {

export function existsSync(dirPath: string) {
// no mock in production
if (process.env.NODE_ENV !== 'test') {
if (!houdini_mode.is_testing) {
return fsExtra.existsSync(dirPath)
}

Expand All @@ -138,7 +139,7 @@ export function existsSync(dirPath: string) {

export async function readdir(filepath: string): Promise<string[]> {
// no mock in production
if (process.env.NODE_ENV !== 'test') {
if (!houdini_mode.is_testing) {
return await fs.readdir(filepath)
}
if (filepath.includes('build/runtime')) {
Expand All @@ -154,7 +155,7 @@ export async function readdir(filepath: string): Promise<string[]> {

export async function remove(filepath: string) {
// no mock in production
if (process.env.NODE_ENV !== 'test') {
if (!houdini_mode.is_testing) {
return await fs.rm(filepath)
}

Expand Down
2 changes: 1 addition & 1 deletion packages/houdini/src/runtime/cache/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ class CacheInternal {

// the cache should always be disabled on the server, unless we're testing
try {
this._disabled = process.env.TEST !== 'true'
this._disabled = process.env.HOUDINI_TEST !== 'true'
} catch {
this._disabled = typeof globalThis.window === 'undefined'
}
Expand Down
4 changes: 2 additions & 2 deletions vitest.setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import * as graphql from 'graphql'
import path from 'path'
import * as recast from 'recast'
import typeScriptParser from 'recast/parsers/typescript'
import { expect, afterEach, beforeEach } from 'vitest'
import { beforeEach, expect } from 'vitest'

import { fs } from './packages/houdini/src/lib'
import { clearMock, testConfig } from './packages/houdini/src/test'

process.env.TEST = 'true'
process.env.HOUDINI_TEST = 'true'

beforeEach(clearMock)

Expand Down

2 comments on commit 927146d

@vercel
Copy link

@vercel vercel bot commented on 927146d Nov 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

docs-next – ./site

docs-next-houdinigraphql.vercel.app
docs-next-git-main-houdinigraphql.vercel.app
docs-next-kohl.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 927146d Nov 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.