Skip to content

Commit

Permalink
Prevent importing integration test-utils
Browse files Browse the repository at this point in the history
  • Loading branch information
bluwy committed Jul 4, 2023
1 parent c9ded7e commit 2eed412
Show file tree
Hide file tree
Showing 12 changed files with 37 additions and 46 deletions.
4 changes: 2 additions & 2 deletions packages/astro/test/units/config/config-server.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect } from 'chai';
import { fileURLToPath } from 'url';
import { defaultLogging as logging } from '../../test-utils.js';
import { defaultLogging } from '../test-utils.js';
import { openConfig } from '../../../dist/core/config/index.js';

const cwd = fileURLToPath(new URL('../../fixtures/config-host/', import.meta.url));
Expand All @@ -11,7 +11,7 @@ describe('config.server', () => {
cwd: flags.root || cwd,
flags,
cmd: 'dev',
logging,
logging: defaultLogging,
});
}

Expand Down
3 changes: 1 addition & 2 deletions packages/astro/test/units/config/format.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import { expect } from 'chai';

import { runInContainer } from '../../../dist/core/dev/index.js';
import { openConfig, createSettings } from '../../../dist/core/config/index.js';
import { createFs } from '../test-utils.js';
import { defaultLogging } from '../../test-utils.js';
import { createFs, defaultLogging } from '../test-utils.js';

const root = new URL('../../fixtures/tailwindcss-ts/', import.meta.url);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import { fileURLToPath } from 'url';
import { validateConfig } from '../../../dist/core/config/config.js';
import { createSettings } from '../../../dist/core/config/index.js';
import { sync as _sync } from '../../../dist/core/sync/index.js';
import { defaultLogging } from '../../test-utils.js';
import { createFsWithFallback } from '../test-utils.js';
import { createFsWithFallback, defaultLogging } from '../test-utils.js';

const root = new URL('../../fixtures/content-mixed-errors/', import.meta.url);
const logging = defaultLogging;
Expand Down
4 changes: 2 additions & 2 deletions packages/astro/test/units/dev/collections-renderentry.test.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { expect } from 'chai';
import * as cheerio from 'cheerio';
import os from 'os';

import { runInContainer } from '../../../dist/core/dev/index.js';
import { createFsWithFallback, createRequestAndResponse } from '../test-utils.js';
import { isWindows } from '../../test-utils.js';
import mdx from '../../../../integrations/mdx/dist/index.js';
import { attachContentServerListeners } from '../../../dist/content/server-listeners.js';

const root = new URL('../../fixtures/content/', import.meta.url);

const describe = isWindows ? global.describe.skip : global.describe;
const describe = os.platform() === 'win32' ? global.describe.skip : global.describe;

async function runInContainerWithContentListeners(params, callback) {
return await runInContainer(params, async (container) => {
Expand Down
9 changes: 2 additions & 7 deletions packages/astro/test/units/dev/hydration.test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { expect } from 'chai';

import { runInContainer } from '../../../dist/core/dev/index.js';
import { createFs, createRequestAndResponse } from '../test-utils.js';
import { createFs, createRequestAndResponse, silentLogging } from '../test-utils.js';
import svelte from '../../../../integrations/svelte/dist/index.js';
import { defaultLogging } from '../../test-utils.js';

const root = new URL('../../fixtures/alias/', import.meta.url);

Expand Down Expand Up @@ -33,11 +32,7 @@ describe('dev container', () => {
{
fs,
root,
logging: {
...defaultLogging,
// Error is expected in this test
level: 'silent',
},
logging: silentLogging,
userConfig: {
integrations: [svelte()],
},
Expand Down
8 changes: 6 additions & 2 deletions packages/astro/test/units/dev/restart.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@ import {
isStarted,
startContainer,
} from '../../../dist/core/dev/index.js';
import { createFs, createRequestAndResponse, triggerFSEvent } from '../test-utils.js';
import {
createFs,
createRequestAndResponse,
defaultLogging,
triggerFSEvent,
} from '../test-utils.js';
import { createSettings, openConfig } from '../../../dist/core/config/index.js';
import { defaultLogging } from '../../test-utils.js';

const root = new URL('../../fixtures/alias/', import.meta.url);

Expand Down
9 changes: 2 additions & 7 deletions packages/astro/test/units/render/components.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ import { expect } from 'chai';
import * as cheerio from 'cheerio';

import { runInContainer } from '../../../dist/core/dev/index.js';
import { createFs, createRequestAndResponse } from '../test-utils.js';
import { createFs, createRequestAndResponse, silentLogging } from '../test-utils.js';
import svelte from '../../../../integrations/svelte/dist/index.js';
import { defaultLogging } from '../../test-utils.js';

const root = new URL('../../fixtures/alias/', import.meta.url);

Expand Down Expand Up @@ -33,11 +32,7 @@ describe('core/render components', () => {
{
fs,
root,
logging: {
...defaultLogging,
// Error is expected in this test
level: 'silent',
},
logging: silentLogging,
userConfig: {
integrations: [svelte()],
},
Expand Down
6 changes: 1 addition & 5 deletions packages/astro/test/units/render/head.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
Fragment,
} from '../../../dist/runtime/server/index.js';
import { createRenderContext, renderPage } from '../../../dist/core/render/index.js';
import { defaultLogging as logging } from '../../test-utils.js';
import { createBasicEnvironment } from '../test-utils.js';
import * as cheerio from 'cheerio';

Expand All @@ -20,10 +19,7 @@ describe('core/render', () => {
describe('Injected head contents', () => {
let env;
before(async () => {
env = createBasicEnvironment({
logging,
renderers: [],
});
env = createBasicEnvironment();
});

it('Multi-level layouts and head injection, with explicit head', async () => {
Expand Down
9 changes: 1 addition & 8 deletions packages/astro/test/units/render/jsx.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,8 @@ import {
renderSlot,
} from '../../../dist/runtime/server/index.js';
import { jsx } from '../../../dist/jsx-runtime/index.js';
import {
createBasicEnvironment,
createRenderContext,
renderPage,
loadRenderer,
} from '../../../dist/core/render/index.js';
import { createRenderContext, renderPage, loadRenderer } from '../../../dist/core/render/index.js';
import { createAstroJSXComponent, renderer as jsxRenderer } from '../../../dist/jsx/index.js';
import { defaultLogging as logging } from '../../test-utils.js';
import { createBasicEnvironment } from '../test-utils.js';

const createAstroModule = (AstroComponent) => ({ default: AstroComponent });
Expand All @@ -24,7 +18,6 @@ describe('core/render', () => {
let env;
before(async () => {
env = createBasicEnvironment({
logging,
renderers: [await loadJSXRenderer()],
});
});
Expand Down
3 changes: 1 addition & 2 deletions packages/astro/test/units/routing/route-matching.test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// @ts-check
import { createFs, createRequestAndResponse } from '../test-utils.js';
import { createFs, createRequestAndResponse, defaultLogging } from '../test-utils.js';
import { createRouteManifest, matchAllRoutes } from '../../../dist/core/routing/index.js';
import { fileURLToPath } from 'url';
import { defaultLogging } from '../../test-utils.js';
import { createViteLoader } from '../../../dist/core/module-loader/vite.js';
import { createDevelopmentEnvironment } from '../../../dist/core/render/dev/environment.js';
import { expect } from 'chai';
Expand Down
16 changes: 15 additions & 1 deletion packages/astro/test/units/test-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,19 @@ import { unixify } from './correct-path.js';
import { getDefaultClientDirectives } from '../../dist/core/client-directive/index.js';
import { createEnvironment } from '../../dist/core/render/index.js';
import { RouteCache } from '../../dist/core/render/route-cache.js';
import { nodeLogDestination } from '../../dist/core/logger/node.js';

/** @type {import('../../src/core/logger/core').LogOptions} */
export const defaultLogging = {
dest: nodeLogDestination,
level: 'error',
};

/** @type {import('../../src/core/logger/core').LogOptions} */
export const silentLogging = {
dest: nodeLogDestination,
level: 'error',
};

class VirtualVolume extends Volume {
#root = '';
Expand Down Expand Up @@ -159,7 +172,7 @@ export const createAstroModule = (AstroComponent) => ({ default: AstroComponent
* @param {Partial<import('../../src/core/render/environment.js').CreateEnvironmentArgs>} options
* @returns {import('../../src/core/render/environment.js').Environment}
*/
export function createBasicEnvironment(options) {
export function createBasicEnvironment(options = {}) {
const mode = options.mode ?? 'development';
return createEnvironment({
...options,
Expand All @@ -171,6 +184,7 @@ export function createBasicEnvironment(options) {
clientDirectives: getDefaultClientDirectives(),
resolve: options.resolve ?? ((s) => Promise.resolve(s)),
routeCache: new RouteCache(options.logging, mode),
logging: options.logging ?? defaultLogging,
ssr: options.ssr ?? true,
streaming: options.streaming ?? true,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,16 @@ import { createLoader } from '../../../dist/core/module-loader/index.js';
import { createRouteManifest } from '../../../dist/core/routing/index.js';
import { createComponent, render } from '../../../dist/runtime/server/index.js';
import { createController, handleRequest } from '../../../dist/vite-plugin-astro-server/index.js';
import { defaultLogging as logging } from '../../test-utils.js';
import {
createAstroModule,
createBasicEnvironment,
createFs,
createRequestAndResponse,
defaultLogging,
} from '../test-utils.js';

async function createDevEnvironment(overrides = {}) {
const env = createBasicEnvironment({
logging,
renderers: [],
});
const env = createBasicEnvironment();
env.settings = await createDefaultDevSettings({}, '/');
env.settings.renderers = [];
env.loader = createLoader();
Expand Down Expand Up @@ -52,7 +49,7 @@ describe('vite-plugin-astro-server', () => {
fsMod: fs,
settings: env.settings,
},
logging
defaultLogging
);

try {
Expand Down

0 comments on commit 2eed412

Please sign in to comment.