Quantcast
Channel: Chutzpah - A JavaScript Test Runner
Viewing all articles
Browse latest Browse all 1864

Edited Unassigned: Code Coverage errors if any uri is a mapped drive path [118]

$
0
0
If you run code coverage against a file on a local or mapped drive, then BlanketJsCoverageEngine fails to convert the URI into a valid file path.

An example stack trace:
```

Chutzpah Error: System.AggregateException: One or more errors occurred. System.NotSupportedException: The given path's format is not supported.
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
at System.IO.StreamReader..ctor(String path, Encoding encoding, Boolean detectEncodingFromByteOrderMarks, Int32 bufferSize, Boolean checkHost)
at System.IO.StreamReader..ctor(String path, Encoding encoding)
at System.IO.File.InternalReadAllLines(String path, Encoding encoding)
at System.IO.File.ReadAllLines(String path)
at Chutzpah.Wrappers.FileSystemWrapper.GetLines(String path)
at Chutzpah.Coverage.BlanketJsCoverageEngine.DeserializeCoverageObject(String json, TestContext testContext)
at Chutzpah.TestCaseStreamReader.ReadFromStream(StreamReader stream, TestContext testContext, ITestMethodRunnerCallback callback, Boolean debugEnabled)
at Chutzpah.TestCaseStreamReader.<>c__DisplayClass1.<Read>b__0()
at System.Threading.Tasks.Task`1.InnerInvoke()
at System.Threading.Tasks.Task.Execute()
--- End of inner exception stack trace ---
at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
at System.Threading.Tasks.Task`1.get_Result()
at Chutzpah.TestCaseStreamReader.Read(ProcessStream processStream, TestOptions testOptions, TestContext testContext, ITestMethodRunnerCallback callback, Boolean debugEnabled)
at Chutzpah.TestRunner.<>c__DisplayClass5.<InvokeTestRunner>b__4(ProcessStream processStream)
at Chutzpah.ProcessHelper.RunExecutableAndProcessOutputT
at Chutzpah.TestRunner.InvokeTestRunner(String headlessBrowserPath, TestOptions options, TestContext testContext, TestRunnerMode testRunnerMode, ITestMethodRunnerCallback callback)
at Chutzpah.TestRunner.<>c__DisplayClass2.<ProcessTestPaths>b__1(PathInfo testFile)
---> (Inner Exception #0) System.NotSupportedException: The given path's format is not supported.
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
at System.IO.StreamReader..ctor(String path, Encoding encoding, Boolean detectEncodingFromByteOrderMarks, Int32 bufferSize, Boolean checkHost)
at System.IO.StreamReader..ctor(String path, Encoding encoding)
at System.IO.File.InternalReadAllLines(String path, Encoding encoding)
at System.IO.File.ReadAllLines(String path)
at Chutzpah.Wrappers.FileSystemWrapper.GetLines(String path)
at Chutzpah.Coverage.BlanketJsCoverageEngine.DeserializeCoverageObject(String json, TestContext testContext)
at Chutzpah.TestCaseStreamReader.ReadFromStream(StreamReader stream, TestContext testContext, ITestMethodRunnerCallback callback, Boolean debugEnabled)
at Chutzpah.TestCaseStreamReader.<>c__DisplayClass1.<Read>b__0()
at System.Threading.Tasks.Task`1.InnerInvoke()
at System.Threading.Tasks.Task.Execute()

```

The bug is due to a limitation of Uri.LocalPath, which does not convert local drive-letter based file paths correctly.

If the URI represents a path of the form:
```
file:///c:/myfile.js
```
Then uri.LocalPath will return:
```
/c:/myfile.js
```
It should return:
```
c:/myfile.js
```
instead. A work-around is to apply the following after getting uri.LocalPath (around line 115 of BlanketJsCoverageEngine.cs):
```
string filePath = uri.LocalPath;

// fix local paths of the form: file:///c:/zzz should become c:/zzz not /c:/zzz
// but keep network paths of the form: file://network/files/zzz as //network/files/zzz
filePath = new Regex(@"^\/([a-zA-Z]:/)").Replace(filePath, "$1");
```
Local drive URIs are incorrect without the three forward-slash characters between file: and the drive letter, but UNC drive-letter paths are invalid with a prefixed forward-slash.

See: http://blogs.msdn.com/b/ie/archive/2006/12/06/file-uris-in-windows.aspx



Viewing all articles
Browse latest Browse all 1864

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>