test: side effects tests should work on Windows

This commit is contained in:
Zoltan Kochan
2022-01-15 03:22:19 +02:00
parent 4bdf7bcacf
commit cdada58d27
6 changed files with 33 additions and 42 deletions

View File

@@ -6,14 +6,12 @@ import { REGISTRY_MOCK_PORT } from '@pnpm/registry-mock'
import { prepareEmpty } from '@pnpm/prepare'
import { ENGINE_NAME } from '@pnpm/constants'
import rimraf from '@zkochan/rimraf'
import isWindows from 'is-windows'
import loadJsonFile from 'load-json-file'
import exists from 'path-exists'
import writeJsonFile from 'write-json-file'
import { testDefaults } from '../utils'
const ENGINE_DIR = `${process.platform}-${process.arch}-node-${process.version.split('.')[0]}`
const skipOnWindows = isWindows() ? test.skip : test
test.skip('caching side effects of native package', async () => {
prepareEmpty()
@@ -71,7 +69,7 @@ test.skip('caching side effects of native package when hoisting is used', async
await project.has('.pnpm/node_modules/es6-promise') // verifying that a flat node_modules was created
})
skipOnWindows('using side effects cache', async () => {
test('using side effects cache', async () => {
prepareEmpty()
// Right now, hardlink does not work with side effects, so we specify copy as the packageImportMethod
@@ -82,13 +80,14 @@ skipOnWindows('using side effects cache', async () => {
sideEffectsCacheWrite: true,
verifyStoreIntegrity: false,
}, {}, {}, { packageImportMethod: 'copy' })
const manifest = await addDependenciesToPackage({}, ['diskusage@1.1.3'], opts)
const manifest = await addDependenciesToPackage({}, ['pre-and-postinstall-scripts-example@1.0.0'], opts)
const filesIndexFile = path.join(opts.storeDir, 'files/10/0c9ac65f21cb83e1d3b9339731937e96d930d0000075d266d3443307659d27759e81f3bc0e87b202ade1f10c4af6845d060b4a985ee6b3ccc4de163a3d2171-index.json')
const filesIndexFile = path.join(opts.storeDir, 'files/2e/28a020ed7c488057d208cd705442e275352fcf88a32b32d0d312668308cb87db3a6df9171ce90d501c3de162b2a6dd5cf62ed7ae8c76532f95adfac924b9a8-index.json')
const filesIndex = await loadJsonFile<PackageFilesIndex>(filesIndexFile)
expect(filesIndex.sideEffects).toBeTruthy() // files index has side effects
expect(filesIndex.sideEffects).toHaveProperty([ENGINE_NAME, 'build/Makefile'])
delete filesIndex.sideEffects![ENGINE_NAME]['build/Makefile']
expect(filesIndex.sideEffects).toHaveProperty([ENGINE_NAME, 'generated-by-preinstall.js'])
expect(filesIndex.sideEffects).toHaveProperty([ENGINE_NAME, 'generated-by-postinstall.js'])
delete filesIndex.sideEffects![ENGINE_NAME]['generated-by-postinstall.js']
await writeJsonFile(filesIndexFile, filesIndex)
await rimraf('node_modules')
@@ -100,10 +99,10 @@ skipOnWindows('using side effects cache', async () => {
storeDir: opts.storeDir,
verifyStoreIntegrity: false,
}, {}, {}, { packageImportMethod: 'copy' })
await addDependenciesToPackage(manifest, ['diskusage@1.1.3'], opts2)
await addDependenciesToPackage(manifest, ['pre-and-postinstall-scripts-example@1.0.0'], opts2)
expect(await exists(path.resolve('node_modules/diskusage/build/Makefile'))).toBeFalsy() // side effects cache correctly used
expect(await exists(path.resolve('node_modules/diskusage/build/binding.Makefile'))).toBeTruthy() // side effects cache correctly used
expect(await exists(path.resolve('node_modules/pre-and-postinstall-scripts-example/generated-by-preinstall.js'))).toBeTruthy() // side effects cache correctly used
expect(await exists(path.resolve('node_modules/pre-and-postinstall-scripts-example/generated-by-postinstall.js'))).toBeFalsy() // side effects cache correctly used
})
test.skip('readonly side effects cache', async () => {
@@ -140,7 +139,7 @@ test.skip('readonly side effects cache', async () => {
expect(await exists(path.join(opts2.storeDir, `localhost+${REGISTRY_MOCK_PORT}/diskusage/1.1.2/side_effects/${ENGINE_DIR}/package/build`))).toBeFalsy()
})
skipOnWindows('uploading errors do not interrupt installation', async () => {
test('uploading errors do not interrupt installation', async () => {
prepareEmpty()
const opts = await testDefaults({
@@ -151,10 +150,11 @@ skipOnWindows('uploading errors do not interrupt installation', async () => {
opts.storeController.upload = async () => {
throw new Error('an unexpected error')
}
await addDependenciesToPackage({}, ['diskusage@1.1.3'], opts)
await addDependenciesToPackage({}, ['pre-and-postinstall-scripts-example@1.0.0'], opts)
expect(await exists('node_modules/diskusage/build')).toBeTruthy()
expect(await exists('node_modules/pre-and-postinstall-scripts-example/generated-by-postinstall.js')).toBeTruthy()
const cacheBuildDir = path.join(opts.storeDir, `localhost+${REGISTRY_MOCK_PORT}/diskusage/1.1.3/side_effects/${ENGINE_DIR}/package/build`)
expect(await exists(cacheBuildDir)).toBeFalsy()
const filesIndexFile = path.join(opts.storeDir, 'files/2e/28a020ed7c488057d208cd705442e275352fcf88a32b32d0d312668308cb87db3a6df9171ce90d501c3de162b2a6dd5cf62ed7ae8c76532f95adfac924b9a8-index.json')
const filesIndex = await loadJsonFile<PackageFilesIndex>(filesIndexFile)
expect(filesIndex.sideEffects).toBeFalsy()
})

View File

@@ -29,7 +29,6 @@
"@types/ramda": "0.27.39",
"@types/rimraf": "^3.0.0",
"@types/sinon": "^10.0.6",
"is-windows": "^1.0.2",
"isexe": "2.0.0",
"load-json-file": "^6.2.0",
"npm-run-all": "^4.1.5",

View File

@@ -1,5 +1,5 @@
{
"dependencies": {
"diskusage": "1.1.3"
"pre-and-postinstall-scripts-example": "1.0.0"
}
}

View File

@@ -1,25 +1,21 @@
lockfileVersion: 5.3
specifiers:
diskusage: 1.1.3
pre-and-postinstall-scripts-example: 1.0.0
dependencies:
diskusage: 1.1.3
pre-and-postinstall-scripts-example: 1.0.0
packages:
/diskusage/1.1.3:
resolution: {integrity: sha512-EAyaxl8hy4Ph07kzlzGTfpbZMNAAAHXSZtNEMwdlnSd1noHzvA6HsgKt4fEMSvaEXQYLSphe5rPMxN4WOj0hcQ==}
/hello-world-js-bin/1.0.0:
resolution: {integrity: sha512-g9DaVvwKClJZUDrsYc7DRhvwMuGLzWlKOJlrHWZz5qiT/RdE1jdT+7Fh1T5XNKW7Oa/pbyxHNz7fK1+vLXe/3w==}
hasBin: true
dev: false
/pre-and-postinstall-scripts-example/1.0.0:
resolution: {integrity: sha512-LiigIO18SIBX0gjNcFRC4nU1L8+Ioysy0NMSZoMIy4fbOm35FxzpDVAcPeFisqbdXPYu166MdlMvla36ySS5qA==}
requiresBuild: true
dependencies:
es6-promise: 4.2.8
nan: 2.14.1
dev: false
/es6-promise/4.2.8:
resolution: {integrity: sha512-HJDGx5daxeIvxdBxvG2cb9g4tEvwIk3i8+nhX0yGrYmZUzbkdg8QbDevheDB8gd0//uPj4c1EQua8Q+MViT0/w==}
dev: false
/nan/2.14.1:
resolution: {integrity: sha512-isWHgVjnFjh2x2yuJ/tj3JbwoHu3UC2dX5G/88Cm24yB6YopVgxvBObDY7n5xW6ExmFhJpSEQqFPvq9zaXc8Jw==}
hello-world-js-bin: 1.0.0
dev: false

View File

@@ -18,7 +18,6 @@ import readprojectsContext from '@pnpm/read-projects-context'
import { REGISTRY_MOCK_PORT } from '@pnpm/registry-mock'
import fixtures from '@pnpm/test-fixtures'
import rimraf from '@zkochan/rimraf'
import isWindows from 'is-windows'
import loadJsonFile from 'load-json-file'
import exists from 'path-exists'
import sinon from 'sinon'
@@ -26,7 +25,6 @@ import writeJsonFile from 'write-json-file'
import testDefaults from './utils/testDefaults'
const f = fixtures(__dirname)
const skipOnWindows = isWindows() ? test.skip : test
test('installing a simple project', async () => {
const prefix = f.prepare('simple')
@@ -673,7 +671,7 @@ test('installing with publicHoistPattern=* in a project with external lockfile',
const ENGINE_DIR = `${process.platform}-${process.arch}-node-${process.version.split('.')[0]}`
skipOnWindows('using side effects cache', async () => {
test('using side effects cache', async () => {
let prefix = f.prepare('side-effects')
// Right now, hardlink does not work with side effects, so we specify copy as the packageImportMethod
@@ -686,13 +684,13 @@ skipOnWindows('using side effects cache', async () => {
}, {}, {}, { packageImportMethod: 'copy' })
await headless(opts)
const cacheIntegrityPath = path.join(opts.storeDir, 'files/10/0c9ac65f21cb83e1d3b9339731937e96d930d0000075d266d3443307659d27759e81f3bc0e87b202ade1f10c4af6845d060b4a985ee6b3ccc4de163a3d2171-index.json')
const cacheIntegrityPath = path.join(opts.storeDir, 'files/2e/28a020ed7c488057d208cd705442e275352fcf88a32b32d0d312668308cb87db3a6df9171ce90d501c3de162b2a6dd5cf62ed7ae8c76532f95adfac924b9a8-index.json')
const cacheIntegrity = await loadJsonFile(cacheIntegrityPath)
expect(cacheIntegrity!['sideEffects']).toBeTruthy()
expect(cacheIntegrity).toHaveProperty(['sideEffects', ENGINE_NAME, 'build/Makefile'])
delete cacheIntegrity!['sideEffects'][ENGINE_NAME]['build/Makefile']
expect(cacheIntegrity).toHaveProperty(['sideEffects', ENGINE_NAME, 'generated-by-postinstall.js'])
delete cacheIntegrity!['sideEffects'][ENGINE_NAME]['generated-by-postinstall.js']
expect(cacheIntegrity).toHaveProperty(['sideEffects', ENGINE_NAME, 'build/binding.Makefile'])
expect(cacheIntegrity).toHaveProperty(['sideEffects', ENGINE_NAME, 'generated-by-preinstall.js'])
await writeJsonFile(cacheIntegrityPath, cacheIntegrity)
prefix = f.prepare('side-effects')
@@ -705,8 +703,8 @@ skipOnWindows('using side effects cache', async () => {
}, {}, {}, { packageImportMethod: 'copy' })
await headless(opts2)
expect(await exists(path.join(prefix, 'node_modules/diskusage/build/Makefile'))).toBeFalsy()
expect(await exists(path.join(prefix, 'node_modules/diskusage/build/binding.Makefile'))).toBeTruthy()
expect(await exists(path.join(prefix, 'node_modules/pre-and-postinstall-scripts-example/generated-by-postinstall.js'))).toBeFalsy()
expect(await exists(path.join(prefix, 'node_modules/pre-and-postinstall-scripts-example/generated-by-preinstall.js'))).toBeTruthy()
})
test.skip('using side effects cache and hoistPattern=*', async () => {

2
pnpm-lock.yaml generated
View File

@@ -1076,7 +1076,6 @@ importers:
'@types/sinon': ^10.0.6
'@zkochan/rimraf': ^2.1.1
dependency-path: workspace:8.0.10
is-windows: ^1.0.2
isexe: 2.0.0
load-json-file: ^6.2.0
npm-run-all: ^4.1.5
@@ -1132,7 +1131,6 @@ importers:
'@types/ramda': 0.27.39
'@types/rimraf': 3.0.2
'@types/sinon': 10.0.6
is-windows: 1.0.2
isexe: 2.0.0
load-json-file: 6.2.0
npm-run-all: 4.1.5