/
githubmirror
/
gutenberg
Обзор
Документация
Войти
/
githubmirror
/
gutenberg
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
trunk
packages/warning/test/babel-plugin.js
96 строк
3 KB
Marco Ciampini
ESLint: Replace strict config with bulk suppressions (#81248)
07 авг 2026, 14:34
Не верифицирован
07 авг 2026, 14:34
7f43eaf
Код
Авторство
О чём код?
import { transform } from '@babel/core'; import babelPlugin from '../babel-plugin'; function join( ...strings ) { return strings.join( '\n' ); } function transformCode( input, options = {} ) { const { code } = transform( input, { configFile: false, plugins: [ [ babelPlugin, options ] ], } ); return code; } describe( 'babel-plugin', () => { it( 'should replace warning calls with import declaration', () => { const input = join( 'import warning from "@wordpress/warning";', 'warning("a");' ); const expected = join( 'import warning from "@wordpress/warning";', 'globalThis.SCRIPT_DEBUG === true ? warning("a") : void 0;' ); expect( transformCode( input ) ).toEqual( expected ); } ); it( 'should not replace warning calls without import declaration', () => { const input = 'warning("a");'; const expected = 'warning("a");'; expect( transformCode( input ) ).toEqual( expected ); } ); it( 'should replace warning calls without import declaration with plugin options', () => { const input = 'warning("a");'; const options = { callee: 'warning' }; const expected = 'globalThis.SCRIPT_DEBUG === true ? warning("a") : void 0;'; expect( transformCode( input, options ) ).toEqual( expected ); } ); it( 'should replace multiple warning calls', () => { const input = join( 'import warning from "@wordpress/warning";', 'warning("a");', 'warning("b");', 'warning("c");' ); const expected = join( 'import warning from "@wordpress/warning";', 'globalThis.SCRIPT_DEBUG === true ? warning("a") : void 0;', 'globalThis.SCRIPT_DEBUG === true ? warning("b") : void 0;', 'globalThis.SCRIPT_DEBUG === true ? warning("c") : void 0;' ); expect( transformCode( input ) ).toEqual( expected ); } ); it( 'should identify warning callee name', () => { const input = join( 'import warn from "@wordpress/warning";', 'warn("a");', 'warn("b");', 'warn("c");' ); const expected = join( 'import warn from "@wordpress/warning";', 'globalThis.SCRIPT_DEBUG === true ? warn("a") : void 0;', 'globalThis.SCRIPT_DEBUG === true ? warn("b") : void 0;', 'globalThis.SCRIPT_DEBUG === true ? warn("c") : void 0;' ); expect( transformCode( input ) ).toEqual( expected ); } ); it( 'should identify warning callee name by', () => { const input = join( 'import warn from "@wordpress/warning";', 'warn("a");', 'warn("b");', 'warn("c");' ); const expected = join( 'import warn from "@wordpress/warning";', 'globalThis.SCRIPT_DEBUG === true ? warn("a") : void 0;', 'globalThis.SCRIPT_DEBUG === true ? warn("b") : void 0;', 'globalThis.SCRIPT_DEBUG === true ? warn("c") : void 0;' ); expect( transformCode( input ) ).toEqual( expected ); } ); } );