|
15 | 15 | //*********************************************************// |
16 | 16 |
|
17 | 17 | using System; |
| 18 | +using System.IO; |
| 19 | +using System.Security.Cryptography; |
18 | 20 |
|
19 | 21 | namespace Microsoft.NodejsTools.TestAdapter.TestFrameworks { |
20 | 22 | class NodejsTestInfo { |
21 | | - public NodejsTestInfo(string fullyQualifiedName) { |
| 23 | + public NodejsTestInfo(string fullyQualifiedName, string modulePath) { |
22 | 24 | string[] parts = fullyQualifiedName.Split(new string[] { "::" }, StringSplitOptions.None); |
23 | 25 | if (parts.Length != 3) { |
24 | 26 | throw new ArgumentException("Invalid fully qualified test name"); |
25 | 27 | } |
26 | | - ModulePath = parts[0]; |
| 28 | + ModulePath = modulePath; |
| 29 | + ModuleName = parts[0]; |
27 | 30 | TestName = parts[1]; |
28 | 31 | TestFramework = parts[2]; |
29 | 32 | } |
30 | 33 |
|
31 | 34 | public NodejsTestInfo(string modulePath, string testName, string testFramework, int line, int column) |
32 | 35 | { |
33 | 36 | ModulePath = modulePath; |
| 37 | + SetModuleName(ModulePath); |
34 | 38 | TestName = testName; |
35 | 39 | TestFramework = testFramework; |
36 | 40 | SourceLine = line; |
37 | 41 | SourceColumn = column; |
38 | 42 | } |
39 | 43 |
|
| 44 | + private void SetModuleName(string modulePath) |
| 45 | + { |
| 46 | + ModuleName = String.Format("{0}[{1}]", |
| 47 | + (string)Path.GetFileName(modulePath).Split('.').GetValue(0), |
| 48 | + GetHash(modulePath)); |
| 49 | + } |
| 50 | + |
| 51 | + private string GetHash(string filePath) |
| 52 | + { |
| 53 | + try |
| 54 | + { |
| 55 | + using (FileStream stream = File.OpenRead(filePath)) |
| 56 | + { |
| 57 | + SHA1Managed sha = new SHA1Managed(); |
| 58 | + byte[] hash = sha.ComputeHash(stream); |
| 59 | + |
| 60 | + // chop hash in half since we just need a unique ID |
| 61 | + Int32 startIndex = hash.Length / 2; |
| 62 | + sha.Dispose(); |
| 63 | + |
| 64 | + return BitConverter.ToString(hash, startIndex).Replace("-", String.Empty); |
| 65 | + } |
| 66 | + } catch (FileNotFoundException) |
| 67 | + { |
| 68 | + // Just return some default value and let node handle it later |
| 69 | + return "FILE_NOT_FOUND"; |
| 70 | + } |
| 71 | + } |
| 72 | + |
40 | 73 | public string FullyQualifiedName { |
41 | 74 | get { |
42 | | - return ModulePath + "::" + TestName + "::" + TestFramework; |
| 75 | + return ModuleName + "::" + TestName + "::" + TestFramework; |
43 | 76 | } |
44 | 77 | } |
45 | 78 | public string ModulePath { get; private set; } |
46 | 79 |
|
| 80 | + public string ModuleName { get; private set; } |
| 81 | + |
47 | 82 | public string TestName { get; private set; } |
48 | 83 |
|
49 | 84 | public string TestFramework { get; private set; } |
|
0 commit comments