Skip to content

Feature Request: specify os in options.json #10252

@JLHwung

Description

@JLHwung

Feature Request

Is your feature request related to a problem? Please describe.
yarn jest is failing on Windows. All the failures are related to the path separator. For example

- var _jsxFileName = "/fake/path/mock.js";
+ var _jsxFileName = "C:\\fake\\path\\mock.js";
Details
FAIL packages/babel-preset-react/test/preset-options.js (5.472s)
  ● babel-preset-react/preset options › development
C:\babel\packages\babel-preset-react\test/fixtures/preset-options/development/exec.js: expect(received).toBe(expected) // Object.is equality

- Expected
+ Received

@@ -1,6 +1,6 @@
- var _jsxFileName = "/fake/path/mock.js";
+ var _jsxFileName = "C:\\fake\\path\\mock.js";
  React.createElement(Foo, {
    bar: "baz",
    __source: {
      fileName: _jsxFileName,
      lineNumber: 1
  1 | const actual = transform('<Foo bar="baz" />', Object.assign({}, opts, {
  2 |   filename: '/fake/path/mock.js'
  3 | })).code;
  4 | const expected = multiline(['var _jsxFileName = "/fake/path/mock.js";', 'React.createElement(Foo, {', '  bar: "baz",', '  __source: {', '    fileName: _jsxFileName,', '    lineNumber: 1', '  },', '  __self: this', '});']);
  5 | expect(actual).toBe(expected);

  3 |   Object.assign({}, opts, { filename: '/fake/path/mock.js' })
  4 | ).code;
> 5 | 
    | ^
  6 | const expected = multiline([
  7 |   'var _jsxFileName = "/fake/path/mock.js";',
  8 |   'React.createElement(Foo, {',

  at packages/babel-preset-react/test/fixtures/preset-options/development/exec.js:5:16
  at runCodeInTestContext (packages/babel-helper-transform-fixture-test-runner/lib/index.js:238:7)
  at run (packages/babel-helper-transform-fixture-test-runner/lib/index.js:305:20)
  at Object.<anonymous> (packages/babel-helper-transform-fixture-test-runner/lib/index.js:430:30)

When we are injecting a file path to the source code, the behavior will be os-dependent. It would be convenient if we can specify os in options.json so that text-runner will run different subset of test cases. The idea comes from #10242 (comment)

Describe the solution you'd like
Specify an os field in options.json,

{
  "os": Array<"windows" | "macos" | "linux" | "freebsd" | "openbsd" | "sunos" | "aix">
}

If os is not specified, it means the test case should be run on every platform we supported.

Example: a test cases specifies

{
  "os": ["macos", "linux"]
}

will only run on Linux and macOS machines.

OS Detection

Map process.platform to normalized name when necessary:

{
  win32: "windows",
  darwin: "macos",
}

Describe alternatives you've considered
Since all of cross-platform test failure comes from path separator, we may also instead define os be of a simplified subset of process.platform

{
  "os": Array<"windows" | "posix">
}

where "posix" = "macos" | "linux" | "freebsd" | "openbsd" | "sunos" | "aix".

Personally I prefer the second approach and we could easily extend our os definitions when we come across other os-dependent issues.

Teachability, Documentation, Adoption, Migration Strategy
This option is for internal use only. It should have no impact on our users.

Previous art

minNodeVersion: #5765.

Related

This feature will work with #10249 to enable windows building on travis.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: testsoutdatedA closed issue/PR that is archived due to age. Recommended to make a new issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions