File tree Expand file tree Collapse file tree 3 files changed +76
-5
lines changed
packages/babel-plugin-relay Expand file tree Collapse file tree 3 files changed +76
-5
lines changed Original file line number Diff line number Diff line change
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @format
8
+ * @oncall relay
9
+ */
10
+
11
+ 'use strict' ;
12
+
13
+ describe ( '`development` option' , ( ) => {
14
+ function transformOnPlatform ( platform : string ) {
15
+ jest . resetModules ( ) ;
16
+
17
+ Object . defineProperty ( process , 'platform' , {
18
+ value : platform ,
19
+ } ) ;
20
+
21
+ jest . doMock ( 'path' , ( ) => {
22
+ if ( platform === 'win32' ) {
23
+ return jest . requireActual ( 'path' ) . win32 ;
24
+ } else {
25
+ return jest . requireActual ( 'path' ) . posix ;
26
+ }
27
+ } ) ;
28
+
29
+ const transformerWithOptions = require ( './transformerWithOptions' ) ;
30
+
31
+ return transformerWithOptions (
32
+ {
33
+ artifactDirectory : '/test/artifacts' ,
34
+ } ,
35
+ 'development' ,
36
+ ) ( 'graphql`fragment TestFrag on Node { id }`' ) ;
37
+ }
38
+
39
+ it ( 'tests the handling of file path' , ( ) => {
40
+ const codeOnPosix = transformOnPlatform ( 'linux' ) ;
41
+ const codeOnNonPosix = transformOnPlatform ( 'win32' ) ;
42
+
43
+ expect ( codeOnNonPosix ) . toEqual ( codeOnPosix ) ;
44
+ expect ( codeOnPosix ) . toMatchSnapshot ( ) ;
45
+ } ) ;
46
+ } ) ;
Original file line number Diff line number Diff line change
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports [` \` development\` option tests the handling of file path 1` ] = `
4
+ "var _TestFrag;
5
+ _TestFrag !== void 0
6
+ ? _TestFrag
7
+ : ((_TestFrag = require('./test/artifacts/TestFrag.graphql')),
8
+ _TestFrag.hash &&
9
+ _TestFrag.hash !== '0bb6b7b29bc3e910921551c4ff5b6757' &&
10
+ console.error(
11
+ \\ "The definition of 'TestFrag' appears to have changed. Run \` relay-compiler\` to update the generated files to receive the expected data.\\ ",
12
+ ),
13
+ _TestFrag);
14
+ "
15
+ ` ;
Original file line number Diff line number Diff line change @@ -29,6 +29,14 @@ const {
29
29
30
30
const GENERATED = './__generated__/' ;
31
31
32
+ /**
33
+ * Converts backslashes in a path to forward slashes (POSIX style) for
34
+ * cross-platform compatibility.
35
+ */
36
+ function posixifyPath ( path : string ) : string {
37
+ return process . platform === 'win32' ? path . replace ( / \\ / g, '/' ) : path ;
38
+ }
39
+
32
40
/**
33
41
* Given a graphql`` tagged template literal, replace it with the appropriate
34
42
* runtime artifact.
@@ -107,11 +115,13 @@ function createNode(
107
115
throw new Error ( 'GraphQL operations and fragments must contain names' ) ;
108
116
}
109
117
const requiredFile = definitionName + '.graphql' ;
110
- const requiredPath = options . isHasteMode
111
- ? requiredFile
112
- : options . artifactDirectory
113
- ? getRelativeImportPath ( state , options . artifactDirectory , requiredFile )
114
- : GENERATED + requiredFile ;
118
+ const requiredPath = posixifyPath (
119
+ options . isHasteMode
120
+ ? requiredFile
121
+ : options . artifactDirectory
122
+ ? getRelativeImportPath ( state , options . artifactDirectory , requiredFile )
123
+ : GENERATED + requiredFile ,
124
+ ) ;
115
125
116
126
const hash = crypto
117
127
. createHash ( 'md5' )
You can’t perform that action at this time.
0 commit comments