Skip to content

Commit

Permalink
fix: ts tests (#984)
Browse files Browse the repository at this point in the history
Using `npm link` ends up deleting folders called "build" from the node_modules folder which is undesirable.

Instead just create the `.bin` directory and symlink aegir into it for testing.
  • Loading branch information
achingbrain committed May 26, 2022
1 parent f18d914 commit 0206c4c
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions test/test.js
Expand Up @@ -5,6 +5,7 @@ import fs, { copy } from 'fs-extra'
import path, { join } from 'path'
import tempy from 'tempy'
import { fileURLToPath } from 'url'
import os from 'os'

const __dirname = path.dirname(fileURLToPath(import.meta.url))

Expand All @@ -16,26 +17,34 @@ async function setUpProject (project) {

await copy(join(__dirname, 'fixtures', 'projects', project), projectDir)
const nodeModulesPath = path.resolve(__dirname, '../node_modules')
const projectNodeModulesPath = path.join(projectDir, 'node_modules')
const aegirPath = path.resolve(__dirname, '..')

// simulate having installed aegir
for (const entry of await fs.readdir(nodeModulesPath)) {
if (entry === '.' || entry === '..') {
if (entry === '.' || entry === '..' || entry === '.bin') {
continue
}

// symlink dep
await fs.createSymlink(path.join(nodeModulesPath, entry), path.join(projectDir, 'node_modules', entry), 'dir')
await fs.createSymlink(path.join(nodeModulesPath, entry), path.join(projectNodeModulesPath, entry), 'dir')
}

// link aegir into project
await execa('npm', ['link', path.resolve(__dirname, '..')], {
cwd: projectDir
})
await fs.mkdir(path.join(projectNodeModulesPath, '.bin'))
await fs.createSymlink(aegirPath, path.join(projectNodeModulesPath, 'aegir'), 'dir')
await fs.createSymlink(path.join(aegirPath, 'src', 'index.js'), path.join(projectNodeModulesPath, '.bin', 'aegir'), 'file')

return projectDir
}

describe('test', () => {
if (os.platform() === 'win32') {
describe.skip('Skipping tests on windows because symlinking works differently', () => {})

return
}

describe('esm', function () {
let projectDir = ''

Expand Down

0 comments on commit 0206c4c

Please sign in to comment.