javaScriptFile returns a callable function to create a JavaScript file on the disk with the given JavaScript source and returns a teardown function to remove the file after its use.
(t *testing.T, js string)
| 1595 | // javaScriptFile returns a callable function to create a JavaScript file on the disk with the |
| 1596 | // given JavaScript source and returns a teardown function to remove the file after its use. |
| 1597 | func javaScriptFile(t *testing.T, js string) func() (path string, teardownFn func()) { |
| 1598 | return func() (path string, teardownFn func()) { |
| 1599 | file, err := os.CreateTemp("", "*.js") |
| 1600 | require.NoError(t, err, "Error creating JavaScript file") |
| 1601 | _, err = file.Write([]byte(js)) |
| 1602 | require.NoError(t, err, "Error writing to JavaScript file") |
| 1603 | path = file.Name() |
| 1604 | teardownFn = func() { |
| 1605 | assert.NoError(t, file.Close(), "Error closing file: %s ", path) |
| 1606 | assert.NoError(t, os.Remove(path), "Error removing file: %s ", path) |
| 1607 | assert.False(t, base.FileExists(path), "File %s should be removed", path) |
| 1608 | } |
| 1609 | return path, teardownFn |
| 1610 | } |
| 1611 | } |
| 1612 | |
| 1613 | // emptyJavaScriptFile returns a callable function to create an empty file on the disk |
| 1614 | // and returns a teardown function to remove the file after its use. |
no test coverage detected