Skip to content

Commit

Permalink
test: fix server port conflict (#7523)
Browse files Browse the repository at this point in the history
  • Loading branch information
sapphi-red committed Apr 4, 2022
1 parent fc51a15 commit ace6e93
Show file tree
Hide file tree
Showing 14 changed files with 43 additions and 17 deletions.
4 changes: 2 additions & 2 deletions packages/playground/cli-module/__tests__/serve.js
Expand Up @@ -5,10 +5,10 @@
const path = require('path')
// eslint-disable-next-line node/no-restricted-require
const execa = require('execa')
const { workspaceRoot } = require('../../testUtils')
const { workspaceRoot, ports } = require('../../testUtils')

const isWindows = process.platform === 'win32'
const port = (exports.port = 9511) // make sure this port is unique across tests with custom servers
const port = (exports.port = ports['cli-module'])
const viteBin = path.join(workspaceRoot, 'packages', 'vite', 'bin', 'vite.js')

/**
Expand Down
4 changes: 2 additions & 2 deletions packages/playground/cli/__tests__/serve.js
Expand Up @@ -5,10 +5,10 @@
const path = require('path')
// eslint-disable-next-line node/no-restricted-require
const execa = require('execa')
const { workspaceRoot } = require('../../testUtils')
const { workspaceRoot, ports } = require('../../testUtils')

const isWindows = process.platform === 'win32'
const port = (exports.port = 9510) // make sure this port is unique across tests with custom servers
const port = (exports.port = ports.cli)
const viteBin = path.join(workspaceRoot, 'packages', 'vite', 'bin', 'vite.js')

/**
Expand Down
@@ -1,10 +1,10 @@
import { getColor, getBgColor } from '../../testUtils'
import { getColor, getBgColor, ports } from '../../testUtils'
import { createServer } from 'vite'
import path from 'path'

// Regression test for https://github.com/vitejs/vite/issues/4000
test('postcss plugins in different dir', async () => {
const port = 5006
const port = ports['css/postcss-plugins-different-dir']
const server = await createServer({
root: path.join(__dirname, '..', '..', 'tailwind'),
logLevel: 'silent',
Expand Down
4 changes: 2 additions & 2 deletions packages/playground/css/postcss-caching/css.spec.ts
@@ -1,9 +1,9 @@
import { getColor } from '../../testUtils'
import { getColor, ports } from '../../testUtils'
import { createServer } from 'vite'
import path from 'path'

test('postcss config', async () => {
const port = 5005
const port = ports['css/postcss-caching']
const startServer = async (root) => {
const server = await createServer({
root,
Expand Down
3 changes: 2 additions & 1 deletion packages/playground/legacy/__tests__/ssr/serve.js
Expand Up @@ -2,8 +2,9 @@
// this is automtically detected by scripts/jestPerTestSetup.ts and will replace
// the default e2e test serve behavior
const path = require('path')
const { ports } = require('../../../testUtils')

const port = (exports.port = 9527)
const port = (exports.port = ports['legacy/ssr'])

/**
* @param {string} root
Expand Down
3 changes: 2 additions & 1 deletion packages/playground/lib/__tests__/serve.js
Expand Up @@ -5,8 +5,9 @@
const path = require('path')
const http = require('http')
const sirv = require('sirv')
const { ports } = require('../../testUtils')

const port = (exports.port = 9527)
const port = (exports.port = ports.lib)

/**
* @param {string} root
Expand Down
3 changes: 2 additions & 1 deletion packages/playground/optimize-missing-deps/__test__/serve.js
Expand Up @@ -3,8 +3,9 @@
// the default e2e test serve behavior

const path = require('path')
const { ports } = require('../../testUtils')

const port = (exports.port = 9529)
const port = (exports.port = ports['optimize-missing-deps'])

/**
* @param {string} root
Expand Down
3 changes: 2 additions & 1 deletion packages/playground/ssr-deps/__tests__/serve.js
Expand Up @@ -3,8 +3,9 @@
// the default e2e test serve behavior

const path = require('path')
const { ports } = require('../../testUtils')

const port = (exports.port = 9530)
const port = (exports.port = ports['ssr-deps'])

/**
* @param {string} root
Expand Down
3 changes: 2 additions & 1 deletion packages/playground/ssr-html/__tests__/serve.js
Expand Up @@ -3,8 +3,9 @@
// the default e2e test serve behavior

const path = require('path')
const { ports } = require('../../testUtils')

const port = (exports.port = 9530)
const port = (exports.port = ports['ssr-html'])

/**
* @param {string} root
Expand Down
3 changes: 2 additions & 1 deletion packages/playground/ssr-pug/__tests__/serve.js
Expand Up @@ -3,8 +3,9 @@
// the default e2e test serve behavior

const path = require('path')
const { ports } = require('../../testUtils')

const port = (exports.port = 9530)
const port = (exports.port = ports['ssr-pug'])

/**
* @param {string} root
Expand Down
3 changes: 2 additions & 1 deletion packages/playground/ssr-react/__tests__/serve.js
Expand Up @@ -3,8 +3,9 @@
// the default e2e test serve behavior

const path = require('path')
const { ports } = require('../../testUtils')

const port = (exports.port = 9528)
const port = (exports.port = ports['ssr-react'])

/**
* @param {string} root
Expand Down
3 changes: 2 additions & 1 deletion packages/playground/ssr-vue/__tests__/serve.js
Expand Up @@ -3,8 +3,9 @@
// the default e2e test serve behavior

const path = require('path')
const { ports } = require('../../testUtils')

const port = (exports.port = 9527)
const port = (exports.port = ports['ssr-vue'])

/**
* @param {string} root
Expand Down
3 changes: 2 additions & 1 deletion packages/playground/ssr-webworker/__tests__/serve.js
Expand Up @@ -3,8 +3,9 @@
// the default e2e test serve behavior

const path = require('path')
const { ports } = require('../../testUtils')

const port = (exports.port = 9528)
const port = (exports.port = ports['ssr-webworker'])

/**
* @param {string} root
Expand Down
17 changes: 17 additions & 0 deletions packages/playground/testUtils.ts
Expand Up @@ -10,6 +10,23 @@ import type { Manifest } from 'vite'
import { normalizePath } from 'vite'
import { fromComment } from 'convert-source-map'

// make sure these ports are unique
export const ports = {
cli: 9510,
'cli-module': 9511,
'legacy/ssr': 9520,
lib: 9521,
'optimize-missing-deps': 9522,
'ssr-deps': 9600,
'ssr-html': 9601,
'ssr-pug': 9602,
'ssr-react': 9603,
'ssr-vue': 9604,
'ssr-webworker': 9605,
'css/postcss-caching': 5005,
'css/postcss-plugins-different-dir': 5006
}

export function slash(p: string): string {
return p.replace(/\\/g, '/')
}
Expand Down

0 comments on commit ace6e93

Please sign in to comment.