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

Fix test db path on Windows #869

Merged
merged 2 commits into from
Jul 23, 2020
Merged

Conversation

Tobbe
Copy link
Member

@Tobbe Tobbe commented Jul 21, 2020

My take on #854

@Tobbe Tobbe force-pushed the tobbe-db-test-path-windows branch 2 times, most recently from 9280643 to 93b8945 Compare July 21, 2020 02:56
@Tobbe
Copy link
Member Author

Tobbe commented Jul 21, 2020

Leaving this PR as a draft for now, because I have not been able to manually test it yet. I build my changes and copy them over with yarn rwt copy ../redwood but then when I try to run my tests I get this

tobbe@XPS9550 MINGW64 ~/dev/redwood/v14
$ yarn rw test
yarn run v1.22.4
$ C:\Users\tobbe\dev\redwood\v14\node_modules\.bin\rw test
internal/modules/cjs/loader.js:1032
  throw err;
  ^

Error: Cannot find module 'lodash-decorators'
Require stack:
- C:\Users\tobbe\dev\redwood\v14\node_modules\@redwoodjs\structure\dist\x\decorators.js
- C:\Users\tobbe\dev\redwood\v14\node_modules\@redwoodjs\structure\dist\ide.js
- C:\Users\tobbe\dev\redwood\v14\node_modules\@redwoodjs\structure\dist\index.js
- C:\Users\tobbe\dev\redwood\v14\node_modules\@redwoodjs\cli\dist\commands\diagnostics.js
- C:\Users\tobbe\dev\redwood\v14\node_modules\yargs\index.js
- C:\Users\tobbe\dev\redwood\v14\node_modules\@redwoodjs\cli\dist\index.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:1029:15)
    at Function.Module._load (internal/modules/cjs/loader.js:898:27)
    at Module.require (internal/modules/cjs/loader.js:1089:19)
    at require (internal/modules/cjs/helpers.js:73:18)
    at Object.<anonymous> (C:\Users\tobbe\dev\redwood\v14\node_modules\@redwoodjs\structure\dist\x\decorators.js:32:25)
    at Module._compile (internal/modules/cjs/loader.js:1200:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1220:10)
    at Module.load (internal/modules/cjs/loader.js:1049:32)
    at Function.Module._load (internal/modules/cjs/loader.js:937:14)
    at Module.require (internal/modules/cjs/loader.js:1089:19) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    'C:\\Users\\tobbe\\dev\\redwood\\v14\\node_modules\\@redwoodjs\\structure\\dist\\x\\decorators.js',
    'C:\\Users\\tobbe\\dev\\redwood\\v14\\node_modules\\@redwoodjs\\structure\\dist\\ide.js',
    'C:\\Users\\tobbe\\dev\\redwood\\v14\\node_modules\\@redwoodjs\\structure\\dist\\index.js',
    'C:\\Users\\tobbe\\dev\\redwood\\v14\\node_modules\\@redwoodjs\\cli\\dist\\commands\\diagnostics.js',
    'C:\\Users\\tobbe\\dev\\redwood\\v14\\node_modules\\yargs\\index.js',
    'C:\\Users\\tobbe\\dev\\redwood\\v14\\node_modules\\@redwoodjs\\cli\\dist\\index.js'
  ]
}
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

@Tobbe
Copy link
Member Author

Tobbe commented Jul 21, 2020

Fixed the missing module error by running yarn install inside node_modules/@redwoodjs/structure

The DB path works in git-bash now. EDIT: Works in PowerShell and cmd as well

@Tobbe
Copy link
Member Author

Tobbe commented Jul 21, 2020

@RobertBroersma Can you take a look at this PR please?

@@ -193,3 +193,15 @@ export const processPagesDir = (
})
return deps
}

export const toPosixPathOnWindows = (path: string) => {
Copy link
Member Author

Choose a reason for hiding this comment

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

If anyone has a better name for this function I'm all ears 👂

Copy link
Contributor

Choose a reason for hiding this comment

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

Make something like ensurePosixPath

packages/cli/src/commands/test.js Show resolved Hide resolved
@RobertBroersma
Copy link
Contributor

Works on my machine and the checks are passing. Nice one!

@peterp
Copy link
Contributor

peterp commented Jul 21, 2020

There's URL_file in structure that might actually do the exact same thing:

export function URL_file(filePath: string, ...parts: string[]): string {
if (filePath.startsWith(FILE_SCHEME))
filePath = filePath.substr(FILE_SCHEME.length)
if (parts.length > 0) filePath = join(filePath, ...parts)
return new URL(FILE_SCHEME + normalize(filePath)).href
}

@Tobbe
Copy link
Member Author

Tobbe commented Jul 21, 2020

I tried using that URL_file function. But it doesn't work. At least not for my use-case.

Here's the output

$ yarn rw test
yarn run v1.22.4
$ C:\Users\tobbe\dev\redwood\redwood-testing\node_modules\.bin\rw test
cacheDirDb file:/c/Users/tobbe/dev/redwood/redwood-testing/node_modules/.redwood/test.db
urlFileName file:///C:/Users/tobbe/dev/redwood/redwood-testing/node_modules/.redwood/test.db
$ C:\Users\tobbe\dev\redwood\redwood-testing\node_modules\.bin\rw db up
Migrate database up... [started]
$ C:\Users\tobbe\dev\redwood\redwood-testing\node_modules\.bin\prisma migrate up --experimental --create-db
Error: Command failed with exit code 255: C:\Users\tobbe\dev\redwood\redwood-testing\node_modules\@prisma\cli\migration-engine-windows.exe cli --datasource file:///C:/Users/tobbe/dev/redwood/redwood-testing/node_modules/.redwood/test.db create-database
Jul 21 19:02:47.919  INFO migration_engine: Starting migration engine CLI git_hash="45c4da4dd3ccd6a322796b228bdf937c7ce884e8"
Jul 21 19:02:47.919 ERROR migration_engine::commands: Creating SQLite database parent directory.

{"is_panic":false,"message":"Creating SQLite database parent directory.\n","backtrace":null}
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Migrate database up... [failed]
→ Command failed with ENOENT: yarn prisma migrate up --experimental --create-db
spawn yarn prisma ENOENT
Command failed with ENOENT: yarn prisma migrate up --experimental --create-db
spawn yarn prisma ENOENT

cacheDirDb is the path "my" code generates, and using that works.
urlFileName is what I get using URL_file, and that doesn't work.

This is how I use URL_file

    const urlFileName = URL_file(`${CACHE_DIR}/test.db`)
    console.log('urlFileName', urlFileName)
    const DATABASE_URL = process.env.TEST_DATABASE_URL || urlFileName

@peterp
Copy link
Contributor

peterp commented Jul 22, 2020

Ah ok, thanks for looking into that for me :)

@Tobbe Tobbe force-pushed the tobbe-db-test-path-windows branch 2 times, most recently from 9ba97b5 to 09c2556 Compare July 22, 2020 12:28
@Tobbe Tobbe marked this pull request as ready for review July 22, 2020 12:49
@peterp
Copy link
Contributor

peterp commented Jul 22, 2020

LGTM!

@peterp peterp added this to the next release milestone Jul 22, 2020
@Tobbe Tobbe force-pushed the tobbe-db-test-path-windows branch from 09c2556 to eb07743 Compare July 22, 2020 18:42
@Tobbe Tobbe force-pushed the tobbe-db-test-path-windows branch from eb07743 to 072d719 Compare July 22, 2020 19:07
@peterp peterp merged commit 4e27429 into redwoodjs:main Jul 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants