@seleniumhq/code-export-csharp-xunit 3.17.2 → 4.0.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/index.js DELETED
@@ -1,180 +0,0 @@
1
- // Licensed to the Software Freedom Conservancy (SFC) under one
2
- // or more contributor license agreements. See the NOTICE file
3
- // distributed with this work for additional information
4
- // regarding copyright ownership. The SFC licenses this file
5
- // to you under the Apache License, Version 2.0 (the
6
- // "License"); you may not use this file except in compliance
7
- // with the License. You may obtain a copy of the License at
8
- //
9
- // http://www.apache.org/licenses/LICENSE-2.0
10
- //
11
- // Unless required by applicable law or agreed to in writing,
12
- // software distributed under the License is distributed on an
13
- // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
- // KIND, either express or implied. See the License for the
15
- // specific language governing permissions and limitations
16
- // under the License.
17
-
18
- import { codeExport as exporter } from '@seleniumhq/side-utils'
19
- import emitter from './command'
20
- import { location } from '@seleniumhq/code-export-csharp-commons'
21
- import { generateHooks } from './hook'
22
- import _default from 'diff-sequences'
23
-
24
- // Define language options
25
- export const displayName = 'C# xUnit'
26
-
27
- export let opts = {}
28
- opts.emitter = emitter
29
- opts.hooks = generateHooks()
30
- opts.fileExtension = '.cs'
31
- opts.commandPrefixPadding = ' '
32
- opts.terminatingKeyword = '}'
33
- opts.commentPrefix = '//'
34
- opts.generateMethodDeclaration = generateMethodDeclaration
35
-
36
- // Create generators for dynamic string creation of primary entities (e.g., filename, methods, test, and suite)
37
- function generateTestDeclaration(name) {
38
- return `[Fact]\npublic void ${exporter.parsers.capitalize(
39
- exporter.parsers.sanitizeName(name)
40
- )}() {`
41
- }
42
-
43
- function generateSuiteDeclaration() {
44
- return `public class SuiteTests : IDisposable {`
45
- }
46
-
47
- function generateMethodDeclaration(name) {
48
- return `public void ${exporter.parsers.sanitizeName(name)}() \n{`
49
- }
50
-
51
- function generateNamespace(name) {
52
- return `namespace ${exporter.parsers.capitalize(
53
- exporter.parsers.sanitizeName(name)
54
- )}\n{\n`
55
- }
56
-
57
- function generateFilename(name) {
58
- return `${exporter.parsers.capitalize(
59
- exporter.parsers.sanitizeName(name)
60
- )}Test${opts.fileExtension}`
61
- }
62
-
63
- // Emit an individual test, wrapped in a suite (using the test name as the suite name)
64
- export async function emitTest({
65
- baseUrl,
66
- test,
67
- tests,
68
- project,
69
- enableOriginTracing,
70
- beforeEachOptions,
71
- enableDescriptionAsComment,
72
- }) {
73
- global.baseUrl = baseUrl
74
- const testDeclaration = generateTestDeclaration(test.name)
75
- const result = await exporter.emit.test(test, tests, {
76
- ...opts,
77
- testDeclaration,
78
- enableOriginTracing,
79
- enableDescriptionAsComment,
80
- project,
81
- })
82
- const suiteName = test.name
83
- const suiteDeclaration = generateSuiteDeclaration()
84
- var _suite = await exporter.emit.suite(result, tests, {
85
- ...opts,
86
- suiteDeclaration,
87
- suiteName,
88
- project,
89
- beforeEachOptions,
90
- })
91
- return {
92
- filename: generateFilename(test.name),
93
- body: exporter.emit.orderedSuite(_suite),
94
- }
95
- }
96
-
97
- // Emit a suite with all of its tests
98
- export async function emitSuite({
99
- baseUrl,
100
- suite,
101
- tests,
102
- project,
103
- enableOriginTracing,
104
- beforeEachOptions,
105
- enableDescriptionAsComment,
106
- }) {
107
- global.baseUrl = baseUrl
108
- const result = await exporter.emit.testsFromSuite(tests, suite, opts, {
109
- enableOriginTracing,
110
- enableDescriptionAsComment,
111
- generateTestDeclaration,
112
- project,
113
- })
114
- const suiteDeclaration = generateSuiteDeclaration()
115
- var _suite = await exporter.emit.suite(result, tests, {
116
- ...opts,
117
- suiteDeclaration,
118
- suite,
119
- project,
120
- beforeEachOptions,
121
- })
122
- return {
123
- filename: generateFilename(suite.name),
124
- body: emitOrderedSuite(_suite, suite.name),
125
- }
126
- }
127
-
128
- function emitOrderedSuite(emittedSuite, name) {
129
- let result = ''
130
- result += emittedSuite.headerComment
131
- result += emittedSuite.dependencies
132
- result += `${generateNamespace(name)}`
133
- result += emittedSuite.suiteDeclaration
134
- result += emittedSuite.variables
135
- //result += emittedSuite.beforeAll
136
- result += emittedSuite.beforeEach
137
- result += emittedSuite.afterEach
138
- //result += emittedSuite.afterAll
139
- result += emittedSuite.methods
140
- if (emittedSuite.tests.testDeclaration) {
141
- const test = emittedSuite.tests
142
- result += test.testDeclaration
143
- result += test.inEachBegin
144
- result += test.commands
145
- result += test.inEachEnd
146
- result += test.testEnd
147
- } else {
148
- for (const testName in emittedSuite.tests) {
149
- const test = emittedSuite.tests[testName]
150
- result += test.testDeclaration
151
- result += test.inEachBegin
152
- result += test.commands
153
- result += test.inEachEnd
154
- result += test.testEnd
155
- }
156
- }
157
- result += emittedSuite.suiteEnd
158
- result += '}' // terminate namespace
159
- return result
160
- }
161
-
162
- export default {
163
- emit: {
164
- test: emitTest,
165
- suite: emitSuite,
166
- locator: location.emit,
167
- command: emitter.emit,
168
- },
169
- register: {
170
- command: emitter.register,
171
- variable: opts.hooks.declareVariables.register,
172
- dependency: opts.hooks.declareDependencies.register,
173
- beforeAll: opts.hooks.beforeAll.register,
174
- beforeEach: opts.hooks.beforeEach.register,
175
- afterEach: opts.hooks.afterEach.register,
176
- afterAll: opts.hooks.afterAll.register,
177
- inEachBegin: opts.hooks.inEachBegin.register,
178
- inEachEnd: opts.hooks.inEachEnd.register,
179
- },
180
- }