Repository: microsoft/griffel
Pull request #223 (2022-09-27 10:10:16)

chore: rework tests init
This reworks tests in `@griffel/babel-preset` to use explicit definitions instead of `fixtures` that uses directory.

This allows to enable/disable tests more transparently and have them described.

github-actions[bot]: ## 📊 Bundle size report

<sub>🤖 This report was generated against <a href='https://github.com/microsoft/griffel/commit/e5edea958cfd18f0583d170f2e6bd14d4d8f77f9'>e5edea958cfd18f0583d170f2e6bd14d4d8f77f9</a></sub>

<!-- Sticky Pull Request Comment -->

Patch:
diff --git a/packages/babel-preset/__fixtures__/config-babel-options/options.json b/packages/babel-preset/__fixtures__/config-babel-options/options.json
deleted file mode 100644
index 7258485..0000000
--- a/packages/babel-preset/__fixtures__/config-babel-options/options.json
+++ /dev/null
@@ -1,5 +0,0 @@
-{
-  "babelOptions": {
-    "plugins": ["./packages/babel-preset/__fixtures__/config-babel-options/colorRenamePlugin"]
-  }
-}
diff --git a/packages/babel-preset/__fixtures__/config-evaluation-rules/options.json b/packages/babel-preset/__fixtures__/config-evaluation-rules/options.json
deleted file mode 100644
index 076f5e0..0000000
--- a/packages/babel-preset/__fixtures__/config-evaluation-rules/options.json
+++ /dev/null
@@ -1,7 +0,0 @@
-{
-  "evaluationRules": [
-    {
-      "action": "sampleEvaluator"
-    }
-  ]
-}
diff --git a/packages/babel-preset/__fixtures__/duplicated-imports/options.json b/packages/babel-preset/__fixtures__/duplicated-imports/options.json
deleted file mode 100644
index d8906ae..0000000
--- a/packages/babel-preset/__fixtures__/duplicated-imports/options.json
+++ /dev/null
@@ -1,3 +0,0 @@
-{
-  "modules": [{ "moduleSource": "custom-package", "importName": "createStylesA" }]
-}
diff --git a/packages/babel-preset/__fixtures__/import-custom-module/options.json b/packages/babel-preset/__fixtures__/import-custom-module/options.json
deleted file mode 100644
index 4d20ffe..0000000
--- a/packages/babel-preset/__fixtures__/import-custom-module/options.json
+++ /dev/null
@@ -1,3 +0,0 @@
-{
-  "modules": [{ "moduleSource": "custom-package", "importName": "makeStyles" }]
-}
diff --git a/packages/babel-preset/__fixtures__/import-custom-name/options.json b/packages/babel-preset/__fixtures__/import-custom-name/options.json
deleted file mode 100644
index 5bb97d6..0000000
--- a/packages/babel-preset/__fixtures__/import-custom-name/options.json
+++ /dev/null
@@ -1,3 +0,0 @@
-{
-  "modules": [{ "moduleSource": "custom-package", "importName": "createStyles" }]
-}
diff --git a/packages/babel-preset/__fixtures__/non-existing-module-call/code.tsx b/packages/babel-preset/__fixtures__/non-existing-module-call/code.ts
similarity index 100%
rename from packages/babel-preset/__fixtures__/non-existing-module-call/code.tsx
rename to packages/babel-preset/__fixtures__/non-existing-module-call/code.ts
diff --git a/packages/babel-preset/__fixtures__/non-existing-module-call/output.tsx b/packages/babel-preset/__fixtures__/non-existing-module-call/output.ts
similarity index 100%
rename from packages/babel-preset/__fixtures__/non-existing-module-call/output.tsx
rename to packages/babel-preset/__fixtures__/non-existing-module-call/output.ts
diff --git a/packages/babel-preset/__fixtures__/require-custom-module/options.json b/packages/babel-preset/__fixtures__/require-custom-module/options.json
deleted file mode 100644
index 4d20ffe..0000000
--- a/packages/babel-preset/__fixtures__/require-custom-module/options.json
+++ /dev/null
@@ -1,3 +0,0 @@
-{
-  "modules": [{ "moduleSource": "custom-package", "importName": "makeStyles" }]
-}


Test patch:
diff --git a/packages/babel-preset/src/transformPlugin.test.ts b/packages/babel-preset/src/transformPlugin.test.ts
index 53f7262..33bfe43 100644
--- a/packages/babel-preset/src/transformPlugin.test.ts
+++ b/packages/babel-preset/src/transformPlugin.test.ts
@@ -27,11 +27,166 @@ pluginTester({
         parser: 'typescript',
       },
     }),
-
-  fixtures: fixturesDir,
   tests: [
+    // 🎩 Tip: use "only: true" to run a single test
+    // https://github.com/babel-utils/babel-plugin-tester#only
+    //
+
+    // Fixtures
+    //
+    //
+    {
+      title: 'assets import handling',
+      fixture: path.resolve(fixturesDir, 'assets', 'code.ts'),
+      outputFixture: path.resolve(fixturesDir, 'assets', 'output.ts'),
+    },
+    {
+      title: 'duplicated imports',
+      fixture: path.resolve(fixturesDir, 'duplicated-imports', 'code.ts'),
+      outputFixture: path.resolve(fixturesDir, 'duplicated-imports', 'output.ts'),
+      pluginOptions: {
+        modules: [{ moduleSource: 'custom-package', importName: 'createStylesA' }],
+      },
+    },
+    {
+      title: 'multiple declarations',
+      fixture: path.resolve(fixturesDir, 'multiple-declarations', 'code.ts'),
+      outputFixture: path.resolve(fixturesDir, 'multiple-declarations', 'output.ts'),
+    },
+    {
+      title: 'call of non existing module',
+      fixture: path.resolve(fixturesDir, 'non-existing-module-call', 'code.ts'),
+      outputFixture: path.resolve(fixturesDir, 'non-existing-module-call', 'output.ts'),
+    },
+
+    // Evaluation
+    //
+    //
+    {
+      title: 'evaluation: mixins via functions',
+      fixture: path.resolve(fixturesDir, 'function-mixin', 'code.ts'),
+      outputFixture: path.resolve(fixturesDir, 'function-mixin', 'output.ts'),
+    },
+    {
+      title: 'evaluation: object',
+      fixture: path.resolve(fixturesDir, 'object', 'code.ts'),
+      outputFixture: path.resolve(fixturesDir, 'object', 'output.ts'),
+    },
+    {
+      title: 'evaluation: object with computed keys',
+      fixture: path.resolve(fixturesDir, 'object-computed-keys', 'code.ts'),
+      outputFixture: path.resolve(fixturesDir, 'object-computed-keys', 'output.ts'),
+    },
+    {
+      title: 'evaluation: object with imported keys',
+      fixture: path.resolve(fixturesDir, 'object-imported-keys', 'code.ts'),
+      outputFixture: path.resolve(fixturesDir, 'object-imported-keys', 'output.ts'),
+    },
+    {
+      title: 'evaluation: object with mixins',
+      fixture: path.resolve(fixturesDir, 'object-mixins', 'code.ts'),
+      outputFixture: path.resolve(fixturesDir, 'object-mixins', 'output.ts'),
+    },
+    {
+      title: 'evaluation: nested objects',
+      fixture: path.resolve(fixturesDir, 'object-nesting', 'code.ts'),
+      outputFixture: path.resolve(fixturesDir, 'object-nesting', 'output.ts'),
+    },
+    {
+      title: 'evaluation: objects with sequence expression',
+      fixture: path.resolve(fixturesDir, 'object-sequence-expr', 'code.ts'),
+      outputFixture: path.resolve(fixturesDir, 'object-sequence-expr', 'output.ts'),
+    },
+    {
+      title: 'evaluation: objects with variables',
+      fixture: path.resolve(fixturesDir, 'object-variables', 'code.ts'),
+      outputFixture: path.resolve(fixturesDir, 'object-variables', 'output.ts'),
+    },
+    {
+      title: 'evaluation: rules with metadata',
+      fixture: path.resolve(fixturesDir, 'rules-with-metadata', 'code.ts'),
+      outputFixture: path.resolve(fixturesDir, 'rules-with-metadata', 'output.ts'),
+    },
+    {
+      title: 'evaluation: shared mixins',
+      fixture: path.resolve(fixturesDir, 'shared-mixins', 'code.ts'),
+      outputFixture: path.resolve(fixturesDir, 'shared-mixins', 'output.ts'),
+    },
+    {
+      title: 'evaluation: tokens scenario',
+      fixture: path.resolve(fixturesDir, 'tokens', 'code.ts'),
+      outputFixture: path.resolve(fixturesDir, 'tokens', 'output.ts'),
+    },
+
+    // Configs
+    //
+    //
+    {
+      title: 'config: babelOptions',
+      fixture: path.resolve(fixturesDir, 'config-babel-options', 'code.ts'),
+      outputFixture: path.resolve(fixturesDir, 'config-babel-options', 'output.ts'),
+      pluginOptions: {
+        babelOptions: {
+          plugins: ['./packages/babel-preset/__fixtures__/config-babel-options/colorRenamePlugin'],
+        },
+      },
+    },
+    {
+      title: 'config: evaluationRules',
+      fixture: path.resolve(fixturesDir, 'config-evaluation-rules', 'code.ts'),
+      outputFixture: path.resolve(fixturesDir, 'config-evaluation-rules', 'output.ts'),
+      pluginOptions: {
+        evaluationRules: [
+          {
+            action: 'sampleEvaluator',
+          },
+        ],
+      },
+    },
+
+    // Imports
+    //
+    //
+    {
+      title: 'imports: alias usage',
+      fixture: path.resolve(fixturesDir, 'import-alias', 'code.ts'),
+      outputFixture: path.resolve(fixturesDir, 'import-alias', 'output.ts'),
+    },
+    {
+      title: 'imports: custom module',
+      fixture: path.resolve(fixturesDir, 'import-custom-module', 'code.ts'),
+      outputFixture: path.resolve(fixturesDir, 'import-custom-module', 'output.ts'),
+      pluginOptions: {
+        modules: [{ moduleSource: 'custom-package', importName: 'makeStyles' }],
+      },
+    },
+    {
+      title: 'imports: custom module name',
+      fixture: path.resolve(fixturesDir, 'import-custom-name', 'code.ts'),
+      outputFixture: path.resolve(fixturesDir, 'import-custom-name', 'output.ts'),
+      pluginOptions: {
+        modules: [{ moduleSource: 'custom-package', importName: 'createStyles' }],
+      },
+    },
+    {
+      title: 'imports: require()',
+      fixture: path.resolve(fixturesDir, 'require', 'code.ts'),
+      outputFixture: path.resolve(fixturesDir, 'require', 'output.ts'),
+    },
+    {
+      title: 'imports: require() with custom module',
+      fixture: path.resolve(fixturesDir, 'require-custom-module', 'code.ts'),
+      outputFixture: path.resolve(fixturesDir, 'require-custom-module', 'output.ts'),
+      pluginOptions: {
+        modules: [{ moduleSource: 'custom-package', importName: 'makeStyles' }],
+      },
+    },
+
+    // Errors
+    //
+    //
     {
-      title: 'Unsupported shorthand CSS properties',
+      title: 'errors: unsupported shorthand CSS properties',
       fixture: path.resolve(fixturesDir, 'unsupported-css-properties', 'fixture.ts'),
       outputFixture: path.resolve(fixturesDir, 'unsupported-css-properties', 'output.ts'),
       setup() {