Skip to content

Commit

Permalink
That's probably sufficient testing
Browse files Browse the repository at this point in the history
  • Loading branch information
NullVoxPopuli committed Feb 5, 2025
1 parent 66dd67a commit be7de2c
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 25 deletions.
22 changes: 20 additions & 2 deletions packages/macros/src/babel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,28 @@ export interface Options {
* Useful for libraries to provide their own config with defaults shared between sub-dependencies of those libraries.
*/
configure?: (macrosInstance: MacrosConfig) => void;

/**
* Override the default directory used for the MacrosConfig
*
* defaults to the CWD, via process.cwd()
*/
dir?: string;
}

interface ConfiguredMacros {
/**
* Array of plugins to add to the babel config plugins array
*/
babelMacros: ReturnType<MacrosConfig['babelPluginConfig']>;
/**
* Array of template transforms to pass to the transforms array of the babel-plugin-ember-template-compilation babel plugin
*/
templateMacros: ReturnType<(typeof MacrosConfig)['transforms']>['plugins'];
}

export function buildMacros(options: Options = {}) {
let root = process.cwd();
export function buildMacros(options: Options = {}): ConfiguredMacros {
let root = options.dir || process.cwd();
let macros = MacrosConfig.for({}, root);

let transforms = MacrosConfig.transforms();
Expand Down
11 changes: 7 additions & 4 deletions packages/macros/tests/babel/dependency-satisfies.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { allBabelVersions, runDefault } from '@embroider/test-support';
import { Project } from 'scenario-tester';
import { join } from 'path';
import { MacrosConfig } from '../../src/node';
import { buildMacros } from '../../src/babel';

const ROOT = process.cwd();

Expand All @@ -21,11 +21,14 @@ describe(`dependencySatisfies`, function () {
includePresetsTests: true,
babelConfig() {
project.write();
let config = MacrosConfig.for({}, project.baseDir);
config.finalize();

let config = buildMacros({
dir: project.baseDir,
});

return {
filename: join(project.baseDir, 'sample.js'),
plugins: config.babelPluginConfig(),
plugins: config.babelMacros,
};
},

Expand Down
47 changes: 28 additions & 19 deletions packages/macros/tests/babel/get-config.test.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
import { allBabelVersions } from '@embroider/test-support';
import { makeBabelConfig, allModes, makeRunner } from './helpers';
import { MacrosConfig } from '../../src/node';
import { allModes, makeRunner } from './helpers';
import { dirname } from 'path';
import { buildMacros } from '../../src/babel';

describe(`getConfig`, function () {
let config: MacrosConfig;
let macros: ReturnType<typeof buildMacros>;
let filename: string;
let run: ReturnType<typeof makeRunner>;

allBabelVersions({
babelConfig(version: number) {
let c = makeBabelConfig(version, config);
c.filename = filename;
babelConfig(_version: number) {
let c = {
filename,
presets: [],
plugins: macros.babelMacros,
};
return c;
},
includePresetsTests: true,
Expand All @@ -24,20 +27,26 @@ describe(`getConfig`, function () {
// we know it will be available.
filename = `${dirname(require.resolve('@embroider/core/package.json'))}/sample.js`;

config = MacrosConfig.for({}, dirname(require.resolve('@embroider/core/package.json')));
config.setOwnConfig(filename, {
beverage: 'coffee',
macros = buildMacros({
dir: dirname(require.resolve('@embroider/core/package.json')),
setOwnConfig: {
beverage: 'coffee',
},
setConfig: {
'@babel/core': [1, 2, 3],
'@babel/traverse': {
sizes: [
{ name: 'small', oz: 4 },
{ name: 'medium', oz: 8 },
],
},
},
configure(config) {
config.setGlobalConfig(filename, 'something-very-global', { year: 2020 });
applyMode(config);
},
});
config.setConfig(filename, '@babel/traverse', {
sizes: [
{ name: 'small', oz: 4 },
{ name: 'medium', oz: 8 },
],
});
config.setConfig(filename, '@babel/core', [1, 2, 3]);
config.setGlobalConfig(filename, 'something-very-global', { year: 2020 });
applyMode(config);
config.finalize();

run = makeRunner(transform);
});

Expand Down

0 comments on commit be7de2c

Please sign in to comment.