Skip to content

Commit fb69f2e

Browse files
committed
Pause Module Changes (Moved out of Preview Namespace)
1 parent 135c24a commit fb69f2e

5 files changed

Lines changed: 151 additions & 10 deletions

File tree

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
testSuite:
2+
testSuiteName: Pause Function Tests
3+
testSuiteDescription: Verifies that the Pause function works correctly
4+
persona: User1
5+
appLogicalName: mda_input_controls_app
6+
7+
testCases:
8+
- testCaseName: Test Pause Function - Non-Headless Mode
9+
testCaseDescription: Tests that Pause function works when headless is false
10+
testSteps: |
11+
=
12+
Screenshot("before_pause.png");
13+
Pause();
14+
Screenshot("after_pause.png");
15+
Assert(true, "Test continued after Pause function");
16+
17+
testSettings:
18+
headless: false
19+
browserConfigurations:
20+
- browser: Chromium
21+
channel: msedge
22+
extensionModules:
23+
enable: true
24+
allowPowerFxNamespaces:
25+
- Preview
26+
environmentVariables:
27+
users:
28+
- personaName: User1
29+
emailKey: user1Email
30+
passwordKey: NotNeeded

src/Microsoft.PowerApps.TestEngine/Modules/TestEngineExtensionChecker.cs

Lines changed: 73 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -311,18 +311,14 @@ public virtual bool Validate(TestSettingExtensions settings, string file)
311311
/// <returns></returns>
312312
public bool VerifyContainsValidNamespacePowerFxFunctions(TestSettingExtensions settings, byte[] assembly)
313313
{
314-
var isValid = true;
315-
316314
#if DEBUG
317-
// Add Experimenal namespaces in Debug compile if it has not been added in allow list
318315
if (!settings.AllowPowerFxNamespaces.Contains(NAMESPACE_PREVIEW))
319316
{
320317
settings.AllowPowerFxNamespaces.Add(NAMESPACE_PREVIEW);
321318
}
322319
#endif
323320

324321
#if RELEASE
325-
// Add Deprecated namespaces in Release compile if it has not been added in deny list
326322
if (!settings.DenyPowerFxNamespaces.Contains(NAMESPACE_DEPRECATED))
327323
{
328324
settings.DenyPowerFxNamespaces.Add(NAMESPACE_DEPRECATED);
@@ -334,6 +330,59 @@ public bool VerifyContainsValidNamespacePowerFxFunctions(TestSettingExtensions s
334330
stream.Position = 0;
335331
ModuleDefinition module = ModuleDefinition.ReadModule(stream);
336332

333+
var isProviderAssembly = module.Types.Any(t =>
334+
t.Interfaces.Any(i =>
335+
i.InterfaceType.FullName == typeof(Providers.ITestWebProvider).FullName ||
336+
i.InterfaceType.FullName == typeof(Users.IUserManager).FullName ||
337+
i.InterfaceType.FullName == typeof(Config.IUserCertificateProvider).FullName));
338+
339+
var isActionModule = module.Types.Any(t => t.Name.EndsWith("Module") &&
340+
!t.Interfaces.Any(i =>
341+
i.InterfaceType.FullName == typeof(Providers.ITestWebProvider).FullName ||
342+
i.InterfaceType.FullName == typeof(Users.IUserManager).FullName ||
343+
i.InterfaceType.FullName == typeof(Config.IUserCertificateProvider).FullName));
344+
345+
bool previewNamespaceEnabled = false;
346+
347+
if (isActionModule)
348+
{
349+
// Generic preview namespace detection for any module with preview support
350+
var previewProperty = module.Types
351+
.Where(t => t.Name.EndsWith("Module"))
352+
.SelectMany(t => t.Properties)
353+
.FirstOrDefault(p => p.Name.Contains("Preview") && p.Name.Contains("Namespace"));
354+
355+
if (previewProperty != null)
356+
{
357+
var moduleWithPreviewSupport = previewProperty.DeclaringType;
358+
359+
#if RELEASE
360+
// In RELEASE mode, check if Preview namespace is in settings
361+
previewNamespaceEnabled = settings.AllowPowerFxNamespaces.Contains(NAMESPACE_PREVIEW);
362+
363+
if (previewNamespaceEnabled)
364+
{
365+
Logger?.LogInformation("RELEASE: Preview namespace enabled based on YAML settings");
366+
}
367+
else
368+
{
369+
Logger?.LogInformation("RELEASE: Preview namespace not enabled in YAML settings");
370+
}
371+
372+
Logger?.LogInformation($"RELEASE: {moduleWithPreviewSupport.Name} detected. Preview namespace enabled: {previewNamespaceEnabled}");
373+
#else
374+
// In DEBUG mode, Preview namespace is already auto-added above
375+
previewNamespaceEnabled = true;
376+
Logger?.LogInformation($"DEBUG: {moduleWithPreviewSupport.Name} detected. Preview namespace auto-enabled in DEBUG mode");
377+
#endif
378+
}
379+
else
380+
{
381+
previewNamespaceEnabled = settings.AllowPowerFxNamespaces.Contains(NAMESPACE_PREVIEW);
382+
Logger?.LogInformation($"Action module without preview support property. Preview namespace enabled from settings: {previewNamespaceEnabled}");
383+
}
384+
}
385+
337386
// Get the source code of the assembly as will be used to check Power FX Namespaces
338387
var code = DecompileModuleToCSharp(assembly);
339388

@@ -352,6 +401,13 @@ public bool VerifyContainsValidNamespacePowerFxFunctions(TestSettingExtensions s
352401
{
353402
foreach (var name in values)
354403
{
404+
// For providers, allow Preview namespace regardless of action module settings
405+
if (name == NAMESPACE_PREVIEW)
406+
{
407+
Logger?.LogInformation($"Allowing Preview namespace for provider {type.Name}");
408+
continue;
409+
}
410+
355411
// Check against deny list using regular expressions
356412
if (settings.DenyPowerFxNamespaces.Any(pattern => Regex.IsMatch(name, WildcardToRegex(pattern))))
357413
{
@@ -382,6 +438,18 @@ public bool VerifyContainsValidNamespacePowerFxFunctions(TestSettingExtensions s
382438
// Extension Module Check are based on constructor
383439
if (type.BaseType != null && type.BaseType.Name == "ReflectionFunction")
384440
{
441+
// For provider assemblies, skip all function validation
442+
if (isProviderAssembly)
443+
{
444+
Logger?.LogInformation($"Skipping function validation for provider assembly function: {type.Name}");
445+
continue;
446+
}
447+
if (isActionModule)
448+
{
449+
// Skip namespace validation for functions in action modules - they're controlled by the module-level logic above
450+
continue;
451+
}
452+
385453
var constructors = type.GetConstructors();
386454

387455
if (constructors.Count() == 0)
@@ -466,7 +534,7 @@ public bool VerifyContainsValidNamespacePowerFxFunctions(TestSettingExtensions s
466534
}
467535
}
468536
}
469-
return isValid;
537+
return true;
470538
}
471539

472540
// Helper method to convert wildcard patterns to regular expressions

src/testengine.module.pause.tests/PauseModuleTests.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,18 @@ public void RegisterPowerFxFunction()
5454
{
5555
// Arrange
5656
var module = new PauseModule();
57+
58+
// Create test settings with Preview namespace enabled
59+
var testSettings = new TestSettings()
60+
{
61+
ExtensionModules = new TestSettingExtensions()
62+
{
63+
AllowPowerFxNamespaces = new HashSet<string> { "Preview" }
64+
}
65+
};
5766

5867
MockSingleTestInstanceState.Setup(x => x.GetLogger()).Returns(MockLogger.Object);
68+
MockTestState.Setup(x => x.GetTestSettings()).Returns(testSettings);
5969

6070
MockLogger.Setup(x => x.Log(
6171
It.IsAny<LogLevel>(),
@@ -71,7 +81,7 @@ public void RegisterPowerFxFunction()
7181
// Assert
7282
MockLogger.Verify(l => l.Log(It.Is<LogLevel>(l => l == LogLevel.Information),
7383
It.IsAny<EventId>(),
74-
It.Is<It.IsAnyType>((v, t) => v.ToString() == "Registered Pause()"),
84+
It.Is<It.IsAnyType>((v, t) => v.ToString() == "Registered Pause() - Preview namespace enabled"),
7585
It.IsAny<Exception>(),
7686
It.IsAny<Func<It.IsAnyType, Exception, string>>()), Times.AtLeastOnce);
7787
}

src/testengine.module.pause/PauseFunction.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public class PauseFunction : ReflectionFunction
2020
private readonly ILogger _logger;
2121

2222
public PauseFunction(ITestInfraFunctions testInfraFunctions, ITestState testState, ILogger logger)
23-
: base(DPath.Root.Append(new DName("Preview")), "Pause", FormulaType.Blank)
23+
: base("Pause", FormulaType.Blank)
2424
{
2525
_testInfraFunctions = testInfraFunctions;
2626
_testState = testState;

src/testengine.module.pause/PauseModule.cs

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,54 @@ namespace testengine.module
1616
[Export(typeof(ITestEngineModule))]
1717
public class PauseModule : ITestEngineModule
1818
{
19+
/// <summary>
20+
/// Indicates whether Preview namespace is enabled in YAML testSettings.extensionModules.allowPowerFxNamespaces.
21+
/// </summary>
22+
public virtual bool IsPreviewNamespaceEnabled { get; private set; } = false;
23+
1924
public void ExtendBrowserContextOptions(BrowserNewContextOptions options, TestSettings settings)
2025
{
21-
26+
UpdatePreviewNamespaceProperty(settings);
2227
}
2328

2429
public void RegisterPowerFxFunction(PowerFxConfig config, ITestInfraFunctions testInfraFunctions, ITestWebProvider testWebProvider, ISingleTestInstanceState singleTestInstanceState, ITestState testState, IFileSystem fileSystem)
2530
{
31+
TestSettings testSettings = null;
32+
try
33+
{
34+
if (testState != null)
35+
{
36+
testSettings = testState.GetTestSettings();
37+
}
38+
}
39+
catch
40+
{
41+
testSettings = null;
42+
}
43+
UpdatePreviewNamespaceProperty(testSettings);
44+
2645
ILogger logger = singleTestInstanceState.GetLogger();
27-
config.AddFunction(new PauseFunction(testInfraFunctions, testState, logger));
28-
logger.LogInformation("Registered Pause()");
46+
47+
// Only register Pause() function if Preview namespace is enabled
48+
if (IsPreviewNamespaceEnabled)
49+
{
50+
config.AddFunction(new PauseFunction(testInfraFunctions, testState, logger));
51+
logger.LogInformation("Registered Pause() - Preview namespace enabled");
52+
}
53+
else
54+
{
55+
logger.LogInformation("Skip registering Pause() - Preview namespace not enabled");
56+
}
2957
}
3058

3159
public async Task RegisterNetworkRoute(ITestState state, ISingleTestInstanceState singleTestInstanceState, IFileSystem fileSystem, IPage Page, NetworkRequestMock mock)
3260
{
3361
await Task.CompletedTask;
3462
}
63+
64+
private void UpdatePreviewNamespaceProperty(TestSettings settings)
65+
{
66+
IsPreviewNamespaceEnabled = settings?.ExtensionModules?.AllowPowerFxNamespaces?.Contains("Preview") ?? false;
67+
}
3568
}
3669
}

0 commit comments

Comments
 (0)