- 
          
- 
                Notifications
    You must be signed in to change notification settings 
- Fork 126
Attempt at speeding up prisma-generator tests #1465
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
          
     Closed
      
      
    
  
     Closed
                    Changes from all commits
      Commits
    
    
            Show all changes
          
          
            8 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      3d342f3
              
                test: speed up prisma-generator tests by pnpm-installing to a test-sp…
              
              
                WimTibackx 408f710
              
                test: Some slight cleanup I forgot
              
              
                WimTibackx bcee249
              
                Apply suggestions from code review
              
              
                WimTibackx 11068cb
              
                Improve error handling along code review comments and document design…
              
              
                WimTibackx 208d1a9
              
                move pnpm-project test utils to testtools package and use from there …
              
              
                WimTibackx 63db458
              
                move main test structure to pnpm
              
              
                WimTibackx f694528
              
                fix out of date pnpm-lock.yaml file
              
              
                WimTibackx 96a92a3
              
                avoid cyclic dependency by expanding the segment of code that is dupl…
              
              
                WimTibackx File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
|  | @@ -8,3 +8,4 @@ dist | |
| coverage | ||
| .build | ||
| .test | ||
| /.pnpm-test-store | ||
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| export * from './db'; | ||
| export * from './model'; | ||
| export * from './schema'; | ||
| export * from './pnpm-project'; | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| import { execSync } from 'node:child_process'; | ||
| import * as fs from 'node:fs'; | ||
| import * as path from 'node:path'; | ||
| import tmp from 'tmp'; | ||
| import { getWorkspaceRoot } from './schema'; | ||
|  | ||
| export const PNPM_STORE_PATH = path.resolve(__dirname, '../../../.pnpm-test-store'); | ||
| export const NPM_RC_FILE = '.npmrc'; | ||
| export const NPM_RC_CONTENTS = `store-dir = ${PNPM_STORE_PATH}`; | ||
| export const PACKAGE_JSON_FILE = 'package.json'; | ||
| export const PACKAGE_JSON_CONTENTS = '{"name":"test-project","version":"1.0.0"}'; | ||
|  | ||
| tmp.setGracefulCleanup(); | ||
|  | ||
| export function preparePackageJson(dependencies: {[key: string]: string} = {}, devDependencies: {[key: string]: string} = {}, includeDefaults: boolean = true): string { | ||
| const tmpDir = tmp.dirSync({ unsafeCleanup: true }).name; | ||
| console.log(`Loading dependencies into store via temp dir ${tmpDir}`); | ||
| try { | ||
| const packageJsonContents = buildPackageJsonContents(dependencies, devDependencies, includeDefaults); | ||
|  | ||
| // I considered doing a `pnpm store add` here instead of a plain install. While that worked, I decided against it in the end because it's a secondary way of processing the dependencies and I didn't see a significant downside to just installing and throwing the local project away right after. | ||
| initProjectDir(tmpDir, packageJsonContents, false); | ||
|  | ||
| return packageJsonContents; | ||
| } finally { | ||
| fs.rmSync(tmpDir, {recursive: true, force: true}); | ||
| } | ||
| } | ||
|  | ||
| export function buildPackageJsonContents(dependencies: {[key: string]: string} = {}, devDependencies: {[key: string]: string} = {}, includeDefaults: boolean = true): string { | ||
| if (includeDefaults) { | ||
| dependencies = { | ||
| "@prisma/client": "^5.14.0", | ||
| "zod": "^3.21.0", | ||
| "decimal.js": "^10.4.0", | ||
| ...dependencies | ||
| }, | ||
| devDependencies = { | ||
| "prisma": "^5.14.0", | ||
| "typescript": "^5.4.0", | ||
| "@types/node": "^20.0.0", | ||
| ...devDependencies | ||
| } | ||
| } | ||
|  | ||
| const absoluteWorkspacePath = getWorkspaceRoot(__dirname); | ||
|  | ||
| return `{ | ||
| "name":"test-project", | ||
| "version":"1.0.0", | ||
| "dependencies": { | ||
| ${Object.entries(dependencies).map(([k, v]) => `"${k}": "${v}"`).join(',\n')} | ||
| }, | ||
| "devDependencies": { | ||
| ${Object.entries(devDependencies).map(([k, v]) => `"${k}": "${v}"`).join(',\n')} | ||
| }, | ||
| "pnpm": { | ||
| "overrides": { | ||
| "@zenstackhq/language": "file:${absoluteWorkspacePath}/packages/language/dist", | ||
| "@zenstackhq/sdk": "file:${absoluteWorkspacePath}/packages/sdk/dist", | ||
| "@zenstackhq/runtime": "file:${absoluteWorkspacePath}/packages/runtime/dist" | ||
| } | ||
| } | ||
| }`; | ||
| } | ||
|  | ||
| export function initProjectDir(projectDir: string, packageJsonContents: string, offline = true) { | ||
| try { | ||
| if (!fs.existsSync(projectDir)) { | ||
| fs.mkdirSync(projectDir, { recursive: true }); | ||
| } | ||
| fs.writeFileSync(path.join(projectDir, PACKAGE_JSON_FILE), packageJsonContents, { flag: 'w+' }); | ||
| fs.writeFileSync(path.join(projectDir, NPM_RC_FILE), NPM_RC_CONTENTS, { flag: 'w+' }); | ||
| } catch (e) { | ||
| console.error(`Failed to set up project dir in ${projectDir}`); | ||
| throw e; | ||
| } | ||
|  | ||
| try { | ||
| execSync(`pnpm install ${offline ? '--prefer-offline ' : ''}--ignore-workspace`, {cwd: projectDir, stdio: 'ignore'}); | ||
| } catch (e) { | ||
| console.error(`Failed to initialize project dependencies in ${projectDir}${offline ? '(offline mode)' : '(online mode)'}`); | ||
| throw e; | ||
| } | ||
| } | 
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.